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;
}
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 5 of 5.
Neethu said:
1 decade ago
#include<stdio.h>
int main()
{
int a=35;
printf("%d %d %d %d %d ",a++,a++,++a,a++,++a);
return 0;
}
OUTPUT gcc: 39 38 40 36 40.
int main()
{
int a=35;
printf("%d %d %d %d %d ",a++,a++,++a,a++,++a);
return 0;
}
OUTPUT gcc: 39 38 40 36 40.
Suresh said:
1 decade ago
Hey @Neethu can you please elaborate this prog at printf function.
Gaurav said:
1 decade ago
The output varies from compiler to compiler.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers