#include<stdio.h>
void main()
{
int i=1;
printf("%d%d%d",i++,++i,i);
}
Answers were Sorted based on User's Feedback
Answer / medo
221...
In printf() function compiler calculates the values from
right to left,but prints the values from left to right.
| Is This Answer Correct ? | 28 Yes | 13 No |
Answer / samrat
The Ans is: 2,3,3
In printf() the evaluation starts from right and the
printing of the values start from left.
Coming from right, the initial value is 1, after that ++i
will increment the value of i to 2. Now i++ will not be
incremented now. It will be incremented after the first "i"
is printed.
So we print 2 first, then the value of i is incremented to 3
(by executing i++). So for the other two i's the value will
be 3. So the ans is 2,3,3
| Is This Answer Correct ? | 13 Yes | 6 No |
Basically in printf the values are calcualted from right to left...and the output is displayed from left to right.
so the output will be
221
first one will be printed
then one will be incremented by one and made as two..since it is a pre increment and will be printed..
then the value now is 2..so it will be printed then it will be incremented { post increment }..
good question..
a typical example for working of Printf
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / prem_mallappa
The right answer is : Unpredictable/implementation defined behaviour.
Why? : get a C faq's book or visit online at c-faq.org
Reason: variable 'i' is changed more thane once between 'sequence point', a sequence point is a semicolon in 'C'. in such cases the result is unknown or compiler dependent.
| Is This Answer Correct ? | 1 Yes | 0 No |
I AM RICKY DOBRIYAL
THIS ANSWER IS DEFINETLY CORRECT
221
BECAUSE COMPILER CALCULATE RIGHT TO LEFT
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / mementomori76
answer is 221, but you shouldn't use void main
it's better to use int main()
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rakesh
121
the first value is post increment(++i) and so at the first compilation the value is not incremented.. the next value is pre increment(i++) so it is incremented at the first compile. the third is the same as the input.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / shahenshah07
its o/p:2 2 1
cause when parameter pass to any f'n its stored in a
stack(lifo).dats y its print i,++i;i++ respectively.
| Is This Answer Correct ? | 0 Yes | 0 No |
how to convert decimal to binary in c using while loop without using array
50 Answers Apple, Aptech, Arwen Tech, BCS, C2D Software, CEC,
How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?
what is run time error?
How to create a program that lists countries capitals when country is entered? (Terribly sorry, I'm a complete novist to coding with C, am looking for inspiration and general tips on how to code and create this program.)
Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;
A sample program using data structure? what is file handling?
what is meant for variable not found?
UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls....
Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.
How to develop a program using C language to convert 8-bit binary values to decimals. TQ
Write a c-programe that input one number of four digits and find digits sum?
printy(a=3,a=2)