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 6 of 7.
OmPrakash said:
1 decade ago
Has anyone compile the code? Do it and you will find '3' is the answer.
Ashish said:
1 decade ago
step 1: i-3;
step 2: i= i; than i++;
step 3: i++ => i=i+1;
so i=4;
step 2: i= i; than i++;
step 3: i++ => i=i+1;
so i=4;
Meghana said:
1 decade ago
@Anjena the answer will be:.
7 9 5 7 (evaluate from right to left).
7 9 5 7 (evaluate from right to left).
Edwin Jose said:
1 decade ago
In post increment i value get incremented in the next step only.
Neha said:
6 years ago
No, The correct answer is 3 because it is i-- (post-increment).
Prof said:
8 years ago
According to me, the answer is 3. Run the code in the compiler.
Ankita khatri said:
8 years ago
It's a post increment and the value of i will be added before.
Anand Sharma said:
7 years ago
As I get the output as 3. I compiled using GCC compiler.
Sakthi said:
2 years ago
It's a post-increment. So the right answer is 3.
(3)
Jyoti said:
7 years ago
As I compiled, I am getting 3 as an output.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers