Classical

C Programming MCQ - Arrays

26:  

The following program

main()
{
  static char a[3][4] = {"abcd", "mnop", "fghi"};
  putchar(**a);
}

A.

will not compile successfully

B.

results in run-time error

C.

prints garbage

D.

none of the above

 
 

Option: D

Explanation :

*a points to the string "abcd".**a is the first character of "abcd", which is the character 'a '


27:  

C does no automatic array bound checking. This is

A.

true

B.

false

C.

C's asset

D.

C's shortcoming

 
 

Option: D

Explanation :

C does no array bound checking. Because of this, one can access fifth clement of an array that is declared to he of lesser size.


28:  

If n has the value 3, then the statement

a [++n] = n++ ;

A.

assigns 3 to a [5]

B.

assigns 4 to a [5]

C.

assigns 4 to a [4]

D.

what is assigned is compiler-dependent

 
 

Option: D

Explanation :


29:  

 Choose the statement that best defines an array

A.

It is a collection of items that share a common name

B.

It is a collection of items that share a common name and occupy consecutive memory location

C.

It is a collection of items of the same type and storage class that share a common name and occupy consecutive memory locations

D.

None of the above

 
 

Option: C

Explanation :


30:  

Choose the correct statements

A.

Strictly speaking C supports 1-dimensional arrays only

B.

An array element may be an array by itself

C.

 Array elements need not occupy contiguous memory locations

D.

Both (a) and (b)

 
 

Option: D

Explanation :

C supports 1-dimensional arrays only. But, the array element can be an array by itself. Using this, one can simulate multi-dimensional arrays. Though at the user level, we use 2-dimen-sional arrays, the compiler interprets this as a 1-dimensional array, each of whose element is a 1-dimensional array. As a matter of fact, a declaration like char [3] [4] , will be interpreted as a 1-dimensional array of size 3 (rather than 4)—each element being a character array of length 4.




Suggest an improvement