C Programming - Expressions - Discussion

Discussion Forum : Expressions - Find Output of Program (Q.No. 12)
12.
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=2;
    printf("%d, %d\n", ++i, ++i);
    return 0;
}
3, 4
4, 3
4, 4
Output may vary from compiler to compiler
Answer: Option
Explanation:

The order of evaluation of arguments passed to a function call is unspecified.

Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.

In TurboC, the output will be 4, 3.

In GCC, the output will be 4, 4.

Discussion:
43 comments Page 3 of 5.

Kartheek said:   9 years ago
In Linux 4,4 because the priority is from right to left. If pre-increment is there from right to left then the variable is updated.

Keerthi said:   1 decade ago
Could you please tell me the exact difference as to why 4 4 is printed in gcc compiler where as 4 3 in turbo c.

Salim shaikh said:   8 years ago
Main
{
int I=23;
int J
J=I++;
Printf(",,...d",J);
}

Please tell me in this case why error occurs?

Sharath said:   1 decade ago
Could you please tell me the exact difference as to why 4 4 is printed in c compiler whereas 4 3 in gcc?

.

Giriprasad said:   7 years ago
It is prinetd in left to right. If it is printed in right to left then the output is 3, 4.
(2)

Ankit kumar said:   9 years ago
It is mentioned here that in GCC compiler output will be 4 4. How? Explain please.

Sonam said:   1 decade ago
What is the difference between ++i and i++. Can anybody explain with an example?

Gangadhar said:   1 decade ago
Then why don't you mention whether it is turbo C compiler or GCC compiler?

Shefali sethiya said:   1 decade ago
Where are the difference between GCC compiler and Turbo C compiler ?

Suresh said:   1 decade ago
Hey @Neethu can you please elaborate this prog at printf function.


Post your comments here:

Your comments will be displayed after verification.