I have a quick question regarding printf statements that I could not find in the C++ reference page.
int x = 0;
Would the output be
I am not sure if incrementing a variable within a printf statement saves the valuable to a variable or not. I never learned the basics of C and want to know how it matches up to C++.
I do understand the pre/post increment but I am worried that doing ++x inside the first printf() won't save if I am incrementing it in the scope of a function.
Best How To :
The output will be 1.
++x will be
x = x+1;
In both the
printf() you get
So the value of x is modified with the pre-increment operator here and in
printf() in the second line prints the new value of x which is
printf() just prints the value of
x it doesn't modify your variable
Note the difference between pre-increment and post-increment .
With post-increment you will get
0 in the first printf() because the value of
x is fetched by the
%d and later
x gets incremented leading to the value of
x in the second prinf() to be