TCS
Company
Programming
Output
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
Read Solution (Total 11)
-
- the answer will be 12,12.
As both are pre increment operators. - 6 years agoHelpfull: Yes(17) No(6)
- The answer is 12,11 since the printf statement executes from right to left.
- 6 years agoHelpfull: Yes(11) No(7)
- ans is 12 12 because printf prints from right to left
so it will first increase the value twice i.e from 1st ++i it will be 11 than for another ++i it will be 12 and than after this both %d will take this 12 as the value and will print - 6 years agoHelpfull: Yes(8) No(1)
- The answer is 11,12.
- 6 years agoHelpfull: Yes(6) No(6)
- ++i is the prefix increment operation.
initially i=10
first , ++i = ++10 = 10+1 = 11
second , ++i = ++11 = 11+1 = 12
So, Output is : 11 , 12. - 6 years agoHelpfull: Yes(6) No(8)
- Printf statement executes from the last so first it prints 11 then prints 12
Ans:12 11 - 6 years agoHelpfull: Yes(3) No(2)
- 12,11 since printf print from right to left
- 6 years agoHelpfull: Yes(1) No(1)
- In the above program output should (11,12) because it follows pre_increment
- 6 years agoHelpfull: Yes(1) No(3)
- Printf frist print value of i and after increase ++i so answer
I=10 after i=11 after increasei=12
Answer is 10 and 11 - 6 years agoHelpfull: Yes(0) No(1)
- Here unary minus (or negation) operator is used twice. Same math rules applies, ie. minus * minus = plus.
Note: However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable. - 6 years agoHelpfull: Yes(0) No(0)
- 11 ,12,first of aall ++i means increment i so int i will incremen two times because two ++i's are there
- 6 years agoHelpfull: Yes(0) No(0)
TCS Other Question
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
Predict the output of following code:
main()
{
int a,x=(2,3,4,5); //valid statement x = last value in list
// x = 5 during declaration list
should be specified inside ( )
a=1,2,3,4,5; // valid; a = 1; first value of the list is
assigned to variable
printf(“%d%d”,x,a);
}
1. Error
2. 5,1
3. 2,1
4. 5,5