ProgrammingHard
struct Cfg { int depth; int width; }; struct Cfg cfg[2] = {{1, 2}, {3, 4}}; struct Cfg *cp = &cfg[1]; cp->width *= 10; printf("%d", cfg[1].width); What is printed?
- A. 4
- B. 30
- C. 40
- D. 34
Correct answer: C. 40
cp points at cfg[1], so the multiplication changes that element. Its width becomes 4 x 10 = 40.
More C Programming questions
- struct Entry { char key[4]; int count; }; struct Entry e[2] = {{"ab", 1}, {"cd", 2}}; printf("%s %d", e[1].key, e[1].count); What is…
- int cmp(const void a, const void b) { return ((const struct Rec )a)->k - ((const struct Rec )b)->k; } Which statement is correct about…
- struct Score { char name[5]; int pts; }; struct Score s = {"Amy", 7}; printf("%d", (int)strlen(s.name)); What is printed?
- struct W { int x; }; struct W w1 = {3}, w2 = {3}; printf("%d", w1.x == w2.x && memcmp(&w1, &w2, sizeof w1) == 0); What is printed (no…
- struct Pack { char a; int b; } p = {'x', 5}; unsigned char raw = (unsigned char )&p; printf("%d", raw[0] == 'x'); What is printed?
- struct Bits { int f : 4; }; struct Bits b; b.f = 3; printf("%d", b.f); What is printed in C for a signed 4-bit field holding 3?