Q38
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
B.
10
C.
50
AnswerD.
30
E.
None of these
Answer: Option C
Solution
Answer: Option C
Solution:
In this case, the type definition typedef char x[10]; creates a new type x, which is an array of 10 characters. Then, an array of 5 elements of type x is declared as x myArray[5];.To calculate the size of
myArray, you can multiply the size of one element (sizeof(x)) by the number of elements (5):sizeof(myArray) = sizeof(x) * 5Since each element
x is an array of 10 characters, and assuming each character occupies 1 byte, the size of x is 10 bytes. Therefore:sizeof(myArray) = 10 bytes * 5 = 50 bytesSo,
sizeof(myArray) will be 50 bytes.