C Programming MCQ - Decision Making & Looping

41:  

The following program fragment

int x[5][5],  i, j;
for (i = 0; i < 5, ++i;)
for(j = 0; j < 5 ; j++)
x[ i ] [ j ] = x[ j ][ i ];

A.

transposes the given matrix x

B.

 makes the given matrix x, symmetric

C.

doesn't alter the matrix x

D.

none of the above

 
 

Option: B

Explanation :

Click on Discuss to view users comments.

Write your comments here:



42:  

Consider the following program segment

i = 6720;
j = 4;
while (( i % j ) == 0) 
{
       i = i / j ;
       j = j + 1;
}


on termination j will have the value

A.

4

B.

8

C.

9

D.

6720

 
 

Option: C

Explanation :

Click on Discuss to view users comments.

Write your comments here:



43:  

 The output of the following program is

main()
{
static int x[ ] = { 1, 2, 3, 4, 5, 6, 7, 8 };
   int i;
for (i = 2; i < 6; ++i )
x[ x[ i ] ] = x[ i ];
for( i =0; i < 8; ++i)
printf("%d", x[ i]);
}

A.

1 2 3 3 5 5 7 8 

B.

1 2 3 4 5 6 7 8

C.

8 7 6 5 4 3 2 1 

D.

1 2 3 5 4 6 7 8

 
 

Option: A

Explanation :

Click on Discuss to view users comments.

Write your comments here:



44:  

Consider the following program

mani( )
{
 int x = 2, y = 5;
   if (x < y)
   return ( x = x + y);
   else printf ("z1");
   printf ("z2");
}


Choose the correct statements

A.

the output is z2

B.

the output is z1z2

C.

this will result in compilation error

D.

none of above

 
 

Option: D

Explanation :

Click on Discuss to view users comments.

neha.jain@gmail.com said: (8:34pm on Thursday 6th June 2013)
output will be z1z2
Susrutha said: (12:55am on Sunday 22nd April 2018)
It will not print thing because there is return statement in if condition.

Write your comments here:



45:  

The for loop
 for( i=0; i<10; ++i)
 printf("%d", i & 1);

prints

A.

0101010101

B.

01111111111

C.

0000000000

D.

111111111

 
 

Option: A

Explanation :

The binary representation of odd numbers will have a 1 as the least significant digit. So, an odd number ANDed with 1, produces a 1 . Even number end with 0. So. an even number ANDed with 1, produces a 0. This for loop generates even and odd numbers alternatively. So. it prints alternate 0's and 1's.

Click on Discuss to view users comments.

Write your comments here: