1)
int i=5;
j=i++ + i++ + i++;
printf("%d",j);This code gives the answer 15.But if we
replace the value of the j then anser is different?why?
2)int i=5;
printf("%d",i++ + i++ + i++);
this givs 18.
Answers were Sorted based on User's Feedback
Answer / venu
i don't know the answer.
but here is the proble.
int i=5;
j=++i + ++i + ++i;
printf("%d",j);This code gives the answer 22.
How and What is the process?
| Is This Answer Correct ? | 62 Yes | 32 No |
Answer / raghu
In the first case
initially j=15 is assigned that is (5+5+5).then i gets incremented thrice.if we try to print i then i will be
8 (5 is incremented thrice).
In the second case
as we know that printf gets evaluated 4m right to left
that is pf("%d", 5++ + 5++ +5++);
that means 4m right to left 7+6+5=18
firstly i's value is 5 then it gets incremented 6 then 7.
| Is This Answer Correct ? | 42 Yes | 14 No |
Answer / gireesh
I have tried the second case in linux with gcc. But, the
output is 15 and not 18.
| Is This Answer Correct ? | 40 Yes | 21 No |
Answer / divakar
in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'
| Is This Answer Correct ? | 26 Yes | 18 No |
Answer / prasoon
both the codes possess undefined behaviour because the value
of i is changing more than once between two sequence points...
hence my answer is undefined behaviour
| Is This Answer Correct ? | 14 Yes | 6 No |
Remember increment operator is compiler depended.
1.
if u compiled in TC++ then u will get j=18
if u compile in VC++ then u will get j=15.
2.
if u compiled in TC++ then u will get j=18
if u compile in VC++ then u will get j=15.
| Is This Answer Correct ? | 14 Yes | 11 No |
Answer / amey
in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'
| Is This Answer Correct ? | 5 Yes | 4 No |
Answer / keerthan
Here, in first case, i=5, j=(i++)+ (i++) + (i++)............ i is added three times without incrementing because it is post incremented so... 5 is added with 5 and again with 5 answer is 15.
where as in second case... execution from right to left when it is done... initially i=5, first i++ this value is 5 then incremented so that 6 is added to 5... now is incremented again so 7 now 7+6+5 =18.
| Is This Answer Correct ? | 0 Yes | 1 No |
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
what is variable length argument list?
main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }
Code for 1>"ascii to string" 2>"string to ascii"
1 Answers Aricent, Global Logic,
given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit
main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }
main() { extern i; printf("%d\n",i); { int i=20; printf("%d\n",i); } }
plz send me all data structure related programs
could you please send the program code for multiplying sparse matrix in c????
main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }
Is it possible to print a name without using commas, double quotes,semi-colons?