ProgrammingHard
struct Node { int v; struct Node *next; }; struct Node *head = NULL; for (int i = 1; i <= 3; i++) { struct Node *n = malloc(sizeof *n); n->v = i * i; n->next = head; head = n; } printf("%d", head->next->v); What is printed?
- A. 4
- B. 9
- C. 1
- D. 0
Correct answer: A. 4
Head insertion puts 9 first, then 4 and then 1. The second node holds 4.
More C Programming questions
- struct Pair { int a; int b; }; struct Pair p = {.b = 4}; printf("%d %d", p.a, p.b); What is printed?
- struct Cfg { int depth; int width; }; struct Cfg cfg[2] = {{1, 2}, {3, 4}}; struct Cfg cp = &cfg[1]; cp->width = 10; printf("%d"…
- 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…