1. Home >
  2. Apps >
  3. Groups >

C code output ?

Question asked by Sachin Jain in #Coffee Room on Dec 25, 2010
Sachin Jain
Sachin Jain · Dec 25, 2010
Rank C2 - EXPERT
Hii
Can anyone please explain me the output of this code

int main()
{
int i=0;
while(+(+i--)!=0)
i -= i++;
printf("%d",i);
getchar();
return 0;
}
I found it at :-
Interview Question for Software Engineer/Developer (Fresher) about CPuzzles « GeeksforGeeks Posted in: #Coffee Room
Varsha0802
Varsha0802 · Dec 25, 2010
Rank C2 - EXPERT
-32768, I guess, because the loop will not run. Tell me if I am correct or not.
deepasri
deepasri · Dec 25, 2010
Rank E2 - BEGINNER
output : -1

in while loop i variable get -1 values then it is true
next statment balance the value as i = -1
then print -1 value.
Sachin Jain
Sachin Jain · Dec 25, 2010
Rank C2 - EXPERT
@deepsari,
You are right its output is -1
Hey, Can you please explain in some steps...
Divisha Madupalli
Divisha Madupalli · Feb 12, 2020
Rank C2 - EXPERT

output is -1

In the while loop, it becomes -1 then the changes do not affect it because the operations are -1 + 0.

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up