#include<stdio.h>
int main()
{
int i=2;
int j=++i + ++i + i++;
printf("%d\n",i);
printf("%d\n",j);
}
Answers were Sorted based on User's Feedback
Answer / gaurav
Please use gcc compiler....u will get answer 1,i.e. 5 and 12
| Is This Answer Correct ? | 10 Yes | 3 No |
Answer / rajesh kumar mahto
i=5 and j=11 (100% correct answer)
this is because
j=5+4+2(right to left execution)
i=5 due to latest updation of i.
| Is This Answer Correct ? | 9 Yes | 5 No |
Answer / kailas.s.patil
i = 2;
first ++i = 3.
second ++i = 4.
third i++ = 5;
now i =5;
then, j = 3 + 4 + 5 = 12
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / kapil
i=5
j=11
j=3+4+4; (i++ post increment)
after this step i value become 5(i++)
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / sanjay
i = 5
j = 11
It is because during the first pre-increment "++i" the compiler gets the value from the memory, increments it and stores it in the memory ie now i = 3. During the second pre-increment "++i" the compiler again gets the value from the memory, increments it, (value in the memory was 3) and so the incremented value is stored again in memory ie i = 4. during the post increment, the value from the memory is received and used in the statement ie) (the whole final statement looks like this ->>( 3 + 4 + 4) ) and then value of i is incremented and stored in memory. thus finally the value of i is 5 and j is 11.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vadim g
i=5 and j=12
Here is the sequence of operations:
1. i = 2 => result i = 2
2. first ++i => result: i = 3
3. second ++i => result: i = 4
4. j assignment => result: j = 4 + 4 + 4 = 12
5. i post increment => i = 5
MSVC++ gives 5 and 12.
| Is This Answer Correct ? | 4 Yes | 3 No |
Are local variables initialized to zero by default in c?
What does the characters “r” and “w” mean when writing programs that will make use of files?
#include<stdio.h> #include<conio.h> void main() { int m=0111,n=20; printf("%d%d\n",m,n); getch(); }
Explain Doubly Linked Lists?
WHAT IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE?
8 Answers Carphone Warehouse, IBM, SAS,
How many levels deep can include files be nested?
compare array with pointer?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
Explain the difference between fopen() and freopen().
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
How many levels of pointers can you have?
What is the function of multilevel pointer in c?