Question 11
Back to Exercise
What is the output of the following C program on a 64-bit system?
#include <stdio.h>
typedef struct {
const char *name;
int marks;
} Student;
int main(void) {
Student cls[] = {{"A", 70}, {"B", 80}, {"C", 90}};
size_t n = sizeof cls / sizeof cls[0];
int sum = 0;
for (size_t i = 0; i < n; i++)
sum += cls[i].marks;
printf("%zu %d\n", n, sum / (int) n);
return 0;
}
- A 3 80 Correct
- B 3 240
- C 16 80
- D 3 0
Correct Answer: Option A
The array size comes from its initializer (3 Students), and sizeof cls / sizeof cls[0] counts them. 240 / 3 = 80.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!