TCS
Company
Programming
Database
#include
int main() {
int i=5;
i=i++ + i++ + i++ + i++ + i++;
printf("%d
",i);
int j=5;
j=++j + ++j + ++j + ++j + ++j;
printf("%d
",j);
return 0;
}
Read Solution (Total 40)
-
- i=i++ + i++ + i++ + i++ + i++;
i=35
j=++j + ++j + ++j + ++j + ++j
j=40 - 9 years agoHelpfull: Yes(13) No(5)
- 3541
like that will be answer because there is no newline tab - 9 years agoHelpfull: Yes(9) No(0)
- printf("%d",i);
the above code will execute the value of i as 35
printf("%d",j);
the above code will execute the value of j as 41 - 9 years agoHelpfull: Yes(7) No(2)
- ya after compilation it gives the i=35 and j=40 post increment operator always works after executing it...so
i=5+5+5+5+5=25 and 5 time increment it will be i=30..
for j=40; pre increment operator work before execution means j=5 after pre increment j=6,j=7,j=8,j=9,j=10;
j=6+7+8+9+10;
j=40 - 9 years agoHelpfull: Yes(5) No(1)
- i=i++ + i++ + i++ + i++ + i++; //post increment ..first put the value of i after that increment i.
so, i=5++ + 5 ++ + 5++ + 5++ + 5++;
i=25 + increment of each
i=30;
j=++j + ++j + ++j + ++j + ++j; //pre increment
j=6+7+8+9+10;
j=40
- 9 years agoHelpfull: Yes(4) No(3)
- ans: i=30,j=50
- 9 years agoHelpfull: Yes(3) No(2)
- The evaluation in C is very different, the answer is 30 and 50
first:
i=i++ + i++ + i++ + i++ + i++;
Since its Post Increment we get the replaceable values as 5.
so, i = 5++ + 5 ++ + 5++ + 5++ + 5++;
so i=25 + increment of each ( five times increment it by 1 )
we get i=30;
Try the same with below to
j=++j + ++j + ++j + ++j + ++j;
Since its Pre Increment we get the replaceable values as (Five time incremented ) 5+1+1+1+1+1 = 10
There fore
j=10+10+10+10+10;
i,e. , j=50
- 9 years agoHelpfull: Yes(2) No(3)
- 3541 will be output
- 6 years agoHelpfull: Yes(2) No(1)
- after running this program in gc compiler output is i=30 and j=40 ..can anyone explain?.is this undefined behavior?
- 9 years agoHelpfull: Yes(1) No(1)
- 1st post increment will be done so it bcms 25 then after increment it will bcm 30
so i=30
for j,1st pre increment will be done so it will be like this 6+7+8+9+10
j=40 - 9 years agoHelpfull: Yes(1) No(1)
- @ KV CHOUDHRI
Please send me TCS placement papers my id: sairam141289@gmail.com - 9 years agoHelpfull: Yes(0) No(0)
- i thinks it answer will be 9 , 10
because during execution it will show the latest value of i and j present in the stack
- 9 years agoHelpfull: Yes(0) No(1)
- ans: i=30,j=40
- 9 years agoHelpfull: Yes(0) No(1)
- frnds the answer purely depends on compiler but going through ansii standards
3540
reason : because increment is right to left associative - 9 years agoHelpfull: Yes(0) No(1)
- i=35
j=40
- 9 years agoHelpfull: Yes(0) No(1)
- i=35 and j = 40;
- 9 years agoHelpfull: Yes(0) No(1)
- i=i++ + i++ + i++ + i ++ + i ++;
(5 + 5 + 5 + 5 + 5 )=25+5=30
j= ++j + ++j + ++j + ++j + ++j;
(6 + 7 + 8+ 9 +10 )=40+2*5 =50
- 9 years agoHelpfull: Yes(0) No(1)
- i=35 and j=40.
- 9 years agoHelpfull: Yes(0) No(1)
- i=35 because here post increment
j=40 and here pre-increment - 9 years agoHelpfull: Yes(0) No(0)
- i=35 and j=40
- 9 years agoHelpfull: Yes(0) No(0)
- i=i++ + i++ + i++ + i++ + i++; i=30 { 5+5+5+5+5=25 then increment five times }
j=++j + ++j + ++j + ++j + ++j; j=50 { first increment five times 10 then 10+10+10+10+10 } - 9 years agoHelpfull: Yes(0) No(0)
- 35 and 40
because in 1st statement i is post increment and and in 2nd j is pre increment. - 9 years agoHelpfull: Yes(0) No(0)
- The increment in I is 35
And increment in j is also 35
So output is 3535 - 9 years agoHelpfull: Yes(0) No(0)
- in the post fix firstly value is assigned then it is incremented...as,5+6+7+8+9=35
on the other hand...prefix firstly increment... as 6+7+8+9+10=40 - 9 years agoHelpfull: Yes(0) No(0)
- i=6+6+6+6+6;
i=30;
j=6+8+10+12+14;
j=50 - 9 years agoHelpfull: Yes(0) No(0)
- i=i++ + i++ + i++ + i++ + ++i;
i=30
j=++j + ++j + ++j + ++j + ++j;
J=40 - 9 years agoHelpfull: Yes(0) No(0)
- i=20,j=50
i=i++ + i++ + i++ + i++ + i++
= 5+5+5+5+5 =20
j=++j + ++ J + ++ j + ++j + ++ j
= 10+10+10+10+10=10*5=50 - 9 years agoHelpfull: Yes(0) No(0)
- 30 and 50
- 9 years agoHelpfull: Yes(0) No(0)
- i=35
j=40
i is first evaluvated (r to l) then increased.
while j is first incremented then evaluvated - 9 years agoHelpfull: Yes(0) No(0)
- i=i++ + i++ + i++ + i++ + i++;
i=25+increament of each=25+5=30;
j=++j + ++j + ++j + ++j + ++j
10 9 8 7 6
10 is distributed among each element. hence j=(10*5)=50;
i=30;
j=50; - 9 years agoHelpfull: Yes(0) No(0)
- 3041
3041
3041 - 9 years agoHelpfull: Yes(0) No(0)
- i= 35 and j=40
- 9 years agoHelpfull: Yes(0) No(0)
- 3540, for i-------------> 5+6+7+8+9,
for j--------------->6+7+8+9+10 - 7 years agoHelpfull: Yes(0) No(0)
- I=5+5+5+5+5=25
j=6+6+6+6+6=30 - 7 years agoHelpfull: Yes(0) No(0)
- first statement is postfix first is print the value after increase the value and second is prefix first is increase the value and after the print value so answer is 35 and 40
- 7 years agoHelpfull: Yes(0) No(0)
- printf("%d",i);
the above code will execute the value of i as 35
printf("%d",j);
the above code will execute the value of j as 41 - 6 years agoHelpfull: Yes(0) No(0)
- i++ =i value is not incremented initially so 5*5=25
but here ++j = j value incremented so 6+7+8+9+10=40
i=25,j=40 - 6 years agoHelpfull: Yes(0) No(0)
- i=9+8+7+6+5=35
J=10+9+8+7+6=40 - 6 years agoHelpfull: Yes(0) No(0)
- i complied it on C................its ...........3541
- 5 years agoHelpfull: Yes(0) No(0)
- I ahve run the code. output is 3541
- 5 years agoHelpfull: Yes(0) No(0)
TCS Other Question