Assume that an integer occupies 4 bytes. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int a[10];
```
printf("%d", sizeof(a) / sizeof(a[0]));
return 0;
```
}
Options
-
A.
4
-
B.
10
-
C.
40
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
10
Detailed Explanation
Correct Answer: 10
The array contains 10 integer elements.
The total size of the array is:
sizeof(a) = 10 × 4 = 40 bytes
The size of one element is:
sizeof(a[0]) = 4 bytes
Therefore:
sizeof(a) / sizeof(a[0]) = 40 / 4 = 10
This is a very common technique in C for finding the number of elements in an array.