TCS
Company
Programming
Predict the output of following code:
main()
{
int i=10,j=2,k=0,m;
m=++i&&++j&&++k; // m = 11 && 3 && 1 = 1
printf(“%d%d%d%d”,i,j,k,m);
}
1.11,3,1,1
2. 11,2,0,1
3. 11,3,1,0
4. 10,2,0,1
Read Solution (Total 4)
-
- 11 3 1 1 since M conditions are satisfied m=1
- 6 years agoHelpfull: Yes(4) No(1)
- 11,3,1,1 as ++I make value of I from 10 to 11 and similarly j valuebecome 3 ad k value become 1 and when we solve && then answer will be 1 .that's why the answer is 11,3,1,1
- 6 years agoHelpfull: Yes(2) No(0)
- 11,3,1,1 since i=10,j=2,k=0
Bcz ++i means 11, ++j means 3,++k means 1
And m = 11 && 3 && 1 =1
So m=1 - 6 years agoHelpfull: Yes(1) No(0)
- Value of i gets increased so i=11
value of j gets increased so j=3
value of k gets increased so k=1
therefore value of m = 1
answer= 1. 11,3,1,1 - 6 years agoHelpfull: Yes(0) No(0)
TCS Other Question
Predict the output of following code:
main()
{
int a=10,x=20;a=a++ + 10; // a = 10+10 first a is increment to 11 but
overwritten by 20
x=x++ + ++a; // x = 20 + 21 a is incremented first from 20 to 21
printf(“%d,%d”,a,x);
}
1. 22,43
2. 12,21
3. 10,20
4. 42,42
Predict the output of following code:
main()
{
int i=10;
printf(“%d,%d”,++i,++i);
}
1. 11,12
2. 12,11
3. 10,11
4. 11,10