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:
71 comments Page 6 of 8.
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:
7 years ago
No, The correct answer is 3 because it is i-- (post-increment).
Prof said:
9 years ago
According to me, the answer is 3. Run the code in the compiler.
Ankita khatri said:
9 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.
Temba bavuma said:
2 months ago
Yes, I agree @Mohamed.
It is indefinite behaviour.
It is indefinite behaviour.
Sakthi said:
3 years ago
It's a post-increment. So the right answer is 3.
(4)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers