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



what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / 123ghouse@gmail.com

3,2,2;

Is This Answer Correct ?    21 Yes 8 No

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

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

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

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

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / rameesh ka

answer is
3,2,2

Is This Answer Correct ?    2 Yes 0 No

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / richa

3,2,2

Is This Answer Correct ?    1 Yes 0 No

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / girish

1,1,3

Is This Answer Correct ?    3 Yes 6 No

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

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

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / sandeep

1,1,2

Is This Answer Correct ?    5 Yes 15 No

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }..

Answer / sebestiraj

1,2,3

Is This Answer Correct ?    1 Yes 14 No

Post New Answer

More C Interview Questions

write a c program that if the given number is prime, and their rearrangement(permute) of that number is also prime. Ex: Input is "197" is prime Output: 791,917,179 is also prime. Please any one tell me tha code for that

3 Answers  


what do the 'c' and 'v' in argc and argv stand for?

0 Answers   TISL,


what is event driven software and what is procedural driven software?

0 Answers  


How is a null pointer different from a dangling pointer?

0 Answers  


What is the difference between void main and main in c?

0 Answers  






how to find the largest element of array without using relational operater?

6 Answers   Satyam, Wipro,


How can you avoid including a header more than once?

0 Answers  


write a program that will print %d in the output screen??

9 Answers   Infosys,


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

0 Answers  


How variables are declared in c?

0 Answers  


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

0 Answers  


Can we change the value of #define in c?

0 Answers  


Categories