plz analyze the output?

S

Sweety

void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
o/p-> 0 3 -1
 
E

E. Robert Tisdale

Something said:
void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
o/p-> 0 3 -1

This is an obvious troll. Please ignore it.
 
K

Keith Thompson

void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
o/p-> 0 3 -1

(See my response to your previous question regarding void main(),
missing "#include <stdio.h>", missing newline, and missing return
value.)

It prints the values of a, b, and c. What exactly are you confused
about?
 
M

Malcolm

Sweety said:
void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
o/p-> 0 3 -1
The increment and decrement operators have side effects. There are rules for
resolving constructs which are ambiguous to a human reader, but they don't
matter, since if code is ambiguous to your human programmer then it is fit
for nothing except the obfusucated C contest.
 
I

Icarus

void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
o/p-> 0 3 -1

the expression (--a,b++)-c is evaluated as follows:
1. the comma expression is evaluated first (in braces).
first a is decremented. (left to right, a is now 0)
the value of a comma exp. is last exp. after comma, in this case it
is b++.
the value of b++ (post increment) is 2 and this is the value of the
comma exp.
the value of b now becomes equal to 3.
2. then from the value of the (..,..) expression c is subracted and
assigned to c. thus c becomes -1.

thus after evaluation:
a==0,b==3,c==-1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top