Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following type definition.

typedef char x[10];

x myArray[5];

What will sizeof(myArray)  be ? (Assume one character occupies 1 byte)

  • A.15 bytes
  • B.10 bytes
  • C.50 bytes
  • D.30 bytes

Answer: C

Correct answer: 50 bytes

The typedef makes x mean char[10]. So x myArray[5] is an array of 5 such arrays:

\[ 5 \times 10 \times 1 = 50 \text{ bytes} \]

A typedef of an array type is easy to misread, because the array-ness is hidden behind the name; expanding it back out is the reliable way to size it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.