what is the output for this question:
main()
{
int i=1;
printf("%d%d%d",i,i++,++i);
}
Answers were Sorted based on User's Feedback
Answer / rama krishna sidhartha
3,2,2 is the correct output. Because the the associativity
of ++ operator is from right to left.
since i=1
++i = 2(since it is a preincrement operator it is
incremented before printing the value)
i++ = 2(since it is a postincrement operator it is
incremented after printing the value)
i = 3
so it is displayed like 3,2,2.
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / r.aruna
answer is 3,2,2
because print the value form right to left.
so,the first one ++i means preincrement.
so,incremented one,2
second one is i++ means postincrement .
it doesn't increment store in same location
but next i means 3.because move to next location
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / sumalatha
Ans is 2 2 2
because in printf assosiativity is from left to right
first pre increments i that becomes 2 next post increment
is done after printf stmt so prints 2 again, then simple
print i i.e 2again
last post increnent which i becomes 3 but that is done
after printf stmt
| Is This Answer Correct ? | 1 Yes | 4 No |
How the processor registers can be used in C ?
why r u join this company? give solid resons.
16 Answers IBM, Infosys, TCS,
Why void is used in c?
how can i sort numbers from ascending order and descending order using turbo c..
What is scanf_s in c?
How can I implement opaque (abstract) data types in C? What's the difference between these two declarations? struct x1 { ... }; typedef struct { ... } x2;
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language
Why main is not a keyword in c?
What is floating point exception error? And what are different types of errors occur during compile time and run time? why they occur?
What is masking?
Can we declare variables anywhere in c?