C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 9)
9.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=3;
i = i++;
printf("%d\n", i);
return 0;
}
Discussion:
70 comments Page 4 of 7.
Sweety said:
9 years ago
Answer will be 3, not 4. Just compile it on another online compiler. And conceptually also it should be 3.
Sneha naik said:
1 decade ago
@Suraj.
Answers will be 4, 3 in post increment value will be assigned later incremented so j=3 and i=4.
Answers will be 4, 3 in post increment value will be assigned later incremented so j=3 and i=4.
Somes Kumar K said:
7 years ago
The ans is 3 not 4,
Here, i=i++ is divided into temp=i; i=i++; i=temp so the i value remains unchanged.
Here, i=i++ is divided into temp=i; i=i++; i=temp so the i value remains unchanged.
(1)
Rupali said:
6 years ago
The answer will be 3 because first the value is assigned to i then it is postdecremented.So i will be 3.
Anjena said:
1 decade ago
Then what abt i-- ? Anyone can clear my doubt?
i=5, j=7;
printf("%d %d %d %d", ++i, ++j, i++, j++);
i=5, j=7;
printf("%d %d %d %d", ++i, ++j, i++, j++);
Gunjan said:
5 years ago
3 is the correct answer.
As x=++i i.e. y=++i
At the place of x, any other variable can be there.
As x=++i i.e. y=++i
At the place of x, any other variable can be there.
Nilesh said:
7 years ago
How answer came 4? It's post-increment operator we 1st assign the value 3 then value will increase
Rohan said:
8 years ago
I tried in the gcc compiler in linux and the output is 3. But here it says 4. How, please explain.
Piyush joshi said:
9 years ago
I tried this code in DEV C++ blog and I got the output as 3. But here, the compiler says 4. Why?
Akanksha said:
10 years ago
Can anyone solve my doubt? What is the output of this?
i = i++ + i++;
printf("%d",i);
i = i++ + i++;
printf("%d",i);
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers