Q. What will be the output of the following C program?
Code:
#include <stdio.h>
int main()
{
int x[5] = { 10, 20, 30 };
printf("%ld", sizeof(x)/sizeof(x[0]));
return 0;
}
β
Correct Answer: (C)
5
Explanation: The statement sizeof(x)/sizeof(x[0]) can be used to get the total numbers of elements, sizeof(x) will return the size of array while sizeof(x[0]) will return the size of first element i.e., size of the type. Their division will return the total number of elements.