C Programming MCQ

1:

The following program

main( )
{
static int a[ ] = { 7, 8, 9 } ;
printf( "%d", 2[ a ] + a[ 2 ] ) ;
}

A.

results in bus error

B.

results in segmentation violation error 

C.

will not compile successfully

D.

none of the above

 

Answer : D

Explanation :

a[2] will be converted to *(a + 2).
*(a + 2) can as well be written as *(2 + a ) .
 *(2 + a ) is nothing but 2 [a] . So. a [2] is essentially same as 2 [a] which is same as * ( 2 + a ). So. it prints 9 + 9 = 18. Some of the modem compilers don't accept 2[a].

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.