main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}

Answers were Sorted based on User's Feedback

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

57 94

{x=y++ + x++;}
equal to
{
x=y+x;//35+20
x++; //56
y++; //36
}

y=++y + ++x;
equal to
{
++y;//37
++x;//57
y=y+x;//37+57
}

So x=57
y=94

 Is This Answer Correct ? 170 Yes 34 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

57
94

 Is This Answer Correct ? 87 Yes 26 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

while calculating the x value,x & y values are post
incremented.So the values of x & y are added and then
incremented i.e. x=56,y=36
while calculating the y value,x & y values are
preincremtned,so x & y values are incremented and then
so x=57
y=57+37=94.

 Is This Answer Correct ? 54 Yes 12 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

56 93.

I will rewrite the above program for ur understand.

int x=20,y=35;
int x1,y1;
x1=y++ + x++; //this line y=35 and x=20 before assign the
value to x.
x=x1; // Value of x1=55, y=36 and x=21.
y1=++y + ++x;//this line y=37 and x=56 before assign the
value to y.
y=y1;// Value of x=56, y=37 and y1=93.
Finally x=56 and y=93

 Is This Answer Correct ? 32 Yes 9 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

Here this should make it easier for you...

Problem_________|___Solution__|

int x=20, y=35; (here the values of x,y are apparent.)

x = y++ + x++; (x=y+x+1) or(x = 35 + 20 + 1)x = 56
But; you incremented y, its now = 36

y = ++y + ++x; (y =(y+1)+(x+1)) or(y=1+36+1+56)y = 94
This is the second time you incremented
x so it is now = 57.

The reason that you are getting different increases
for x and y is that when you use statement(x=x++) you are
first stating that x is = to x, and then 'increment x.
when you use statemnt(x=++x) you are first
stating 'increment x, then that x is = to x.

look at the code and description in the chart below.

table:
code = meaning;
int x=2
int y=2
-------------------|
(x=x++) = "x = x, x + 1" (increment happens after)
(x=++x) = "x = (x+1)" (increment happens before)
(x=y++) = "x = y, y + 1" (increment happens after)
(x=++y) = "x = (y+1)" (increment happens before)

if you want to add y to x and then increment y use this
statement:

x+=y++

if you want to increment y and then add it to x use this
statement:

x+=++y

 Is This Answer Correct ? 24 Yes 7 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

57 94

 Is This Answer Correct ? 33 Yes 18 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

x=57
y=94

 Is This Answer Correct ? 29 Yes 14 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

 Is This Answer Correct ? 15 Yes 11 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

56 93

 Is This Answer Correct ? 5 Yes 3 No

main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf(&q..

The program results in an undefined behaviour. You're wrong
http://en.wikipedia.org/wiki/Sequence_point

 Is This Answer Correct ? 4 Yes 4 No

More C Interview Questions

How can I implement sets or arrays of bits?

i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } printf("%d", k);

write a c program to check weather a particluar bit is set or not?

what is the difference between declaration ,defenetion and initialization of a variable?

identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

How to write a code for reverse of string without using string functions?

swap two integer variables without using a third temporary variable?

What is "Hungarian Notation"?

c program to subtract between two numbers without using '-' sign and subtract function.

Explain how can I pad a string to a known length?

why program counter is 16 bit?

what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

Categories