ProgrammingHard
struct Q { int v; }; struct Q q[3] = {{5}, {1}, {3}}; struct Q *lo = q; for (int i = 1; i < 3; i++) if (q[i].v < lo->v) lo = &q[i]; printf("%d", lo->v); What is printed?
- A. 5
- B. 3
- C. 1
- D. 0
Correct answer: C. 1
lo starts at the first element, 5, and is replaced by 1 at index 1. 3 is not smaller than 1, so lo keeps 1.
More C Programming questions
- struct T { int a; double d; }; printf("%d", (int)(sizeof(struct T) == 16)); What is printed with 4-byte int and 8-byte double (natural…
- struct F { char c; double d; }; printf("%zu", sizeof(struct F)); What is printed with natural alignment and 8-byte double?
- struct G { int x; char y[3]; }; printf("%zu", sizeof(struct G)); What is printed with 4-byte int and natural alignment?
- struct H { short s; char c; }; printf("%zu", sizeof(struct H)); What is printed with 2-byte short and natural alignment?
- union U { int i; char c[6]; }; printf("%zu", sizeof(union U)); What is printed with 4-byte int and 1-byte char?
- struct E { int n; int a[]; }; printf("%zu", sizeof(struct E)); What is printed for a struct with a flexible array member and 4-byte int?