main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
Answer Posted / joseph
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 ? | 25 Yes | 7 No |
Post New Answer View All Answers
Explain modulus operator.
In C programming, how do you insert quote characters (‘ and “) into the output screen?
What is string constants?
What is #include conio h?
Is it fine to write void main () or main () in c?
What is the use of bitwise operator?
Why doesnt the call scanf work?
What are different types of operators?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
How to write a multi-statement macro?
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
Why header file is used in c?
How important is structure in life?
Linked lists -- can you tell me how to check whether a linked list is circular?
What is a c token and types of c tokens?