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 3 of 7.
Ankita khatri said:
8 years ago
It's a post increment and the value of i will be added before.
Prof said:
8 years ago
According to me, the answer is 3. Run the code in the compiler.
Gudimalla said:
7 years ago
According to me, it is 3.
Anand Sharma said:
7 years ago
As I get the output as 3. I compiled using GCC compiler.
Nilesh said:
7 years ago
How answer came 4? It's post-increment operator we 1st assign the value 3 then value will increase
Jyoti said:
7 years ago
As I compiled, I am getting 3 as an output.
GuruSudharshan said:
8 years ago
Hi All, Answer is wrong and the correct answer is 3, how means;
int i=3;
i=i++;
in above line i post incremented but result (i++ value is 3 in current line)3 is assigned to i.
So final output is 3.
(if you want output as 4 try this,
int i=3;
i=++i;
)
int i=3;
i=i++;
in above line i post incremented but result (i++ value is 3 in current line)3 is assigned to i.
So final output is 3.
(if you want output as 4 try this,
int i=3;
i=++i;
)
Meghna Anam said:
6 years ago
I have compiled this program and I get output 3.
So, the correct answer is 3.
So, the correct answer is 3.
Neha said:
6 years ago
No, The correct answer is 3 because it is i-- (post-increment).
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers