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
if p is a string contained in a string?
How is a macro different from a function?
What is getch() function?
Why c is called procedure oriented language?
Differentiate between the = symbol and == symbol?
What are the application of c?
What is a 'null pointer assignment' error?
a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none
Write a program to swap two numbers without using the third variable?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
What is the equivalent code of the following statement in WHILE LOOP format?
i have a written test for microland please give me test pattern
What should malloc() do?
Hi can anyone tell what is a start up code?
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.