C Programming MCQ - Decision Making & Looping

11:  

Which is true of conditional compilation ?

A.

it is taken care of by the compiler

B.

 it is taken care of by the pre-processor

C.

it is compiling a program based on a condition

D.

both (b) & (c)

 
 

Option: D

Explanation :

Click on Discuss to view users comments.

Write your comments here:



12:  

Consider the following program fragment

 char c = ' a ';
 while ( c++ <= ' z ')
 putchar ( xxx );


If the required output is abcdefghijklmnopqrstuvwxyz, then xxx should be

A.

c

B.

c++

C.

c-1

D.

-c

 
 

Option: C

Explanation :

Click on Discuss to view users comments.

Write your comments here:



13:  

Choose the statements that are syntactically correct

A.

/*  Is /* this a valid */ comment */

B.

for ( ; ; ) ;

C.

return;

D.

both (b) & (c)

 
 

Option: D

Explanation :

Click on Discuss to view users comments.

Write your comments here:



14:  

The following program fragment

for(i = 3 ; i < 15; i += 3);
printf(" %d ", i);


results in

A.

a syntax error

B.

an execution error

C.

printing of 12

D.

printing of 15

 
 

Option: D

Explanation :

Click on Discuss to view users comments.

Alok Gupta said: (7:11pm on Friday 26th April 2013)
I think it should print 12 as, there is no equality sign with condition 'i<15' so, when i become 15, this condition become false and loop breaks. Second thing that I need to ask is, does this printf statement is within for loop or outside the loop. If it is inside the loop, then it will print multiple outputs and that should be '3' '6' '9' and '12'. If it is outside then yes it will print 15 but then you should at-least use delimiter to signify that.
Alok Gupta said: (7:13pm on Friday 26th April 2013)
And yes it will results in the syntax error as, at the end of the for loop there is one semi-colon and that is incorrect.

Write your comments here:



15:  

The following program fragment

for (i = 1; i< 5; ++ i )
if ( i == 3) continue;
else printf( " %d " i );


results in the printing of

A.

1 2 4 5

B.

1 2 4

C.

2 4 5

D.

none of the above

 
 

Option: B

Explanation :

The use of continue statement forces the execution to skip the remainder of the current pass over the loop and initiates the next. If ' U ' is 3. print f statement will be skipped. Hence the answer is b

Click on Discuss to view users comments.

Write your comments here: