?
Consider the following type definition.
Consider the following type definition.
typedef char x[10];
x myArray[5];
What will sizeof(myArray) be ? (Assume one character occupies 1 byte)
typedef char x[10];
x myArray[5];
Answer & Solution
Correct Answer:
Option
C
In this case, the type definition
To calculate the size of
Since each element
So,
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.
Join the Discussion
Login to post a comment or share your explanation.
LoginX myArray[5];
X=5
Then
5*10=50
so: 10*5=50
10 of X and 5 of myarray
since myarray = 5 and x = 10
therefore, 5 * 10 = 50
therefore x myarray[5] it means 10*5=50 is the right answer.]