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

What is the use of linkage in c language?

0 Answers  


any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

0 Answers  


1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.

4 Answers  


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

1 Answers   91mobiles, Amazon, App Guruz, College School Exams Tests, Folio3, Infosys, Omega, Planin, Riphah International University, Subex,


Can u please send me the exam pattern and also Previous papers to javed123go@gmail.com

0 Answers  






Why the below program throughs error during compilation? #include<stdio.h> #include<conio.h> enum { ZERO, ONE, TWO, }; main() { printf("%d",&TWO); getch(); }

2 Answers  


Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

0 Answers  


What are pointers? What are stacks and queues?

0 Answers   Hexaware,


difference of two no's with out using - operator

7 Answers  


Do you know what are the properties of union in c?

0 Answers  


what are brk, sbrk?

1 Answers   Oracle,


What is the purpose of main() function?

0 Answers  


Categories