Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual studio (std::cout) not printing my variable value
    primarykey
    data
    text
    <p>I am so confused why the cout statement is not printing the contents of the array c_braces_array in the function find_depth;</p> <p>All I am trying to do is pass an array and print its values.</p> <pre><code>#include &lt;iostream&gt; int find_depth(char c_braces_array[], int no_of_braces) { for(int i=0; i&lt;no_of_braces; i++) { std::cout&lt;&lt;"val is:"&lt;&lt;c_braces_array[i]&lt;&lt;"F\n"; } return 0; } int main() { char braces[100] = {0}; int ret_val = find_depth(braces, 100); std::cout&lt;&lt;ret_val; system ("pause"); return 0; } </code></pre> <p>O/P:</p> <blockquote> <p>...<br/> val is: F<br/> val is: F<br/> val is: F<br/> val is: F<br/> val is: F<br/> 0Press any key to continue . . .<br/></p> </blockquote> <p><img src="https://i.stack.imgur.com/8zECb.png" alt="enter image description here"></p> <p>Edit: I initialized the array to contain all 0s in the main. So I was expecting 0s to be printed. I am not sure where the O (as in Oh!) thing comes into context. Can someone explain a bit more on that?</p> <p>I was expecting this o/p</p> <blockquote> <p>val is:0 F<br/></p> </blockquote> <p>Edit - 2: Guys thanks. Thanks for pointing out the bug. Also I do not understand why the following line initializes only braces[0] with 'a' instead of the entire array. WHat is the correct way to init the entire array instead of running a for loop.</p> <p>Now my code looks as below.</p> <pre><code>main(){ ... char a_char = 'a'; char braces[100] = {a_char}; } find_depth(..) { ... std::cout&lt;&lt;"val is:"&lt;&lt;c_braces_array_ptr[i]&lt;&lt;"X\n"; } </code></pre> <p>O/P <br/> Inside main: a <br/> val is:aX <br/> val is: X <br/> val is: X <br/> val is: X <br/> val is: X <br/> val is: X <br/> val is: X <br/> val is: X <br/></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload