ProgrammingHardIBM · Deloitte pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Student {
char name[10];
int marks[3];
};
struct Student s = {"Bob", {80, 90, 70}};
int total = 0;
for (int i = 0; i < 3; i++) total += s.marks[i];
printf("%s %d", s.name, total);- A. Bob 240
- B. Bob 80
- C. Compile-time error: cannot initialise an array member with a nested brace list
- D. Undefined behaviour: marks is accessed as a flexible array member
Correct answer: A. Bob 240
marks is a perfectly ordinary fixed-size array member (int marks[3];), initialised via a nested brace-enclosed list {80, 90, 70}, which is standard C syntax. Summing all three gives 80+90+70=240.
More C Programming questions
- Assume 32-bit int. What is printed? c int x = 1; int y = 2; int z = 3; int result = x + y == z; printf("%d", result);
- What happens when this runs? c int divide(int result, int a, int b) { if (b == 0) return -1; result = a / b; return 0; } int main(void) {…
- Assume 32-bit int. What is printed? c int x = 3; int result = x++ + x++ - x++; printf("%d", result); printf(" valid: %s", "no, undefined…
- What is printed? c int main(void) { int a[3] = {1, 2, 3}; int b[3] = {1, 2, 3}; printf("%d", a == b); }
- What is printed? c int main(void) { char a[] = "test"; char b[] = "test"; printf("%d %d", a == b, strcmp(a, b) == 0); }
- What is printed? c int main(void) { int x = 100; long y = x; long long z = y 1000000000L; printf("%lld", z); }