You are on page 1of 4

1.

Answer: Option D
Explanation:
Step 1: int i = 0; here variable i is an integer type and initialized to '0'.
Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semi-
colon at the end of this for loop tells, "there is no more statement is inside the loop".
Loop 1: here i=0, the condition in for! 0"#$! i%%& loop satisfies and then i is incremented
by '''one&
Loop 2: here i=1, the condition in for! '"#$! i%%& loop satisfies and then i is incremented
by '''one&
Loop 3: here i=2, the condition in for! ("#$! i%%& loop satisfies and then i is incremented
by '''one&
Loop 4: here i=3, the condition in for! )"#$! i%%& loop satisfies and then i is increemented
by '''one&
Loop 5: here i=4, the condition in for! *"#$! i%%& loop satisfies and then i is incremented
by '''one&
Loop 6: here i=5, the condition in for! $"#$! i%%& loop satisfies and then i is incremented
by '''one&
Loop 7: here i=6, the condition in for! +"#$! i%%& loop fails and then i is not incremented.
Step 3: printf("%d", i); here the value of i is +. ,ence the output is '+'.
2. Answer: Option D
Explanation:
-nitially variables a = 500, b = 100 and c is not assigned.
Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(F!"#) ,ence the if condition is failed.
Step 5: .o, variable c is assigned to a value '(00'.
Step 6: printf("b = %d c = %d$n", b, c); -t prints value of b and c.
,ence the output is "b # '00 c # (00"
3 . Answer: Option A
Explanation:
,ere %n&i'n(d int size is ( bytes. -t varies from 0,',(,), ... to +$$)$.
Step 1:%n&i'n(d int i = 65535;
Step 2:
Loop 1: )*i+((i++ != 0) this statement becomes )*i+((65535 != 0). ,ence
the )*i+((,-.#) condition is satisfied. Then the printf("%d", ++i); prints
'''variable /i/ is already increemented by ''' in /hile statement and no/ increemented by
''' in printf statement& Loop 2: )*i+((i++ != 0) this statement becomes )*i+((1 !=
0). ,ence the )*i+((,-.#) condition is satisfied. Then theprintf("%d", ++i); prints
')'variable /i/ is already increemented by ''' in /hile statement and no/ increemented by
''' in printf statement&
....
....
The /hile loop /ill never stops e0ecuting, because variable i /ill never become '0'zero&.
,ence it is an '-nfinite loop'.
4. Answer: Option A
Explanation:
for(i<=5 00 i>=11; ++i; i>0) so e0pression i<=5 00 i>=11 initializes forloop.
e0pression ++i is the loop condition. e0pression i>0 is the increment e0pression.
-n for( i <= 5 00 i >= 11; ++i; i>0) e0pression i<=5 00 i>=11 evaluates to one.
1oop condition al/ays get evaluated to tr%(. 2lso at this point it increases i by one.
2n increment3e0pression i>0 has no effect on value of i.so for loop get e0ecuted till the limit
of integer ie. +$$)$&
5. Answer: Option B
Explanation:
printf() returns the number of charecters printed on the console.
Step 1: if(c* = printf("")) here printf() does not print anything, so it returns
'0'zero&.
Step 2: if(c* = 0) here variable ch has the value '0'zero&.
Step 3: if(0) ,ence the if condition is not satisfied. .o it prints the (+&(statements.
,ence the output is "-t doesn't matters".
4ote: 5ompiler sho/s a /arning "possibly incorrect assinment".
6. Answer: Option D
Explanation:
,ere %n&i'n(d int size is ( bytes. -t varies from 0,',(,), ... to +$$)$.
Step 1:%n&i'n(d int i = 65536; here variable i becomes '0'zero&. because%n&i'n(d
int varies from 0 to +$$)$.
Step 2: )*i+((i != 0) this statement becomes )*i+((0 != 0). ,ence
the)*i+((F!"#) condition is not satisfied. .o, the inside the statements of )*i+(loop /ill
not get e0ecuted.
,ence there is no output.
4ote: 6on't forget that the size of int should be ( bytes. -f you run the above program in 755
it may run infinite loop, because in 1inu0 platform the size of the integer is * bytes.
7. Answer: Option A
Explanation:
if(023 > a) here a is a float variable and 023 is a double constant. The double
constant 023 is greater than the float variable a. ,ence the if condition is satisfied and it
prints /4i/
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.8000000000 0.+999999::'
8. Answer: Option C
Explanation:
Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and
initialized to 0, ', ) respectively.
Step 2: 5((a) 6 0b 7 0a) = a 6 b 7 c; The right side of the e0pression(a6
b7c) becomes (06173). ,ence it return the value ')'.
The left side of the e0pression 5((a) 6 0b 7 0a) becomes 5((0) 6 0b 7 0a). ,ence
this contains the address of the variable a 5(0a).
Step 3: 5((a) 6 0b 7 0a) = a 6 b 7 c; ;inally this statement becomes <=a&#).
,ence the variable a has the value ')'.
Step 4: printf("%d, %d, %d$n", a, b, c); -t prints "), ', )".
9. Answer: Option C
Explanation:
The +o'ica+ not operator ta>es e0pression and evaluates to true if the e0pression is false
and evaluates to false if the e0pression is true. -n other /ords it reverses the value of the
e0pression.
Step 1: if(!(!8) 00 8)
Step 2: if(!(!10) 00 10)
Step 3: if(!(0) 00 10)
Step 3: if(1 00 10)
Step 4: if(,-.#) here the if condition is satisfied. ,ence it prints 8 = 10.
10. d
11. a
12. C
9o&t d(cr(:(nt op(rator fir&t a&&i'n t*( ;a+%( t*(n
it d(cr(:(nt& t*( ;a+%(2
n%: = 1a<1
n%: = 15
=o) ;a+%( of ;ariab+( a )i++ b( 42
13. A
14. B
15. C

You might also like