ProgrammingHard
struct N { int v; struct N *next; } *a = NULL; for (int i = 1; i <= 3; i++) { struct N *n = malloc(sizeof *n); n->v = i; n->next = a; a = n; } printf("%d", a->next->v); What is printed?
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: B. 2
Head insertion makes the last inserted node, 3, first. Its next node is 2, which is printed.
More C Programming questions
- Two pointers p and q point into the same block allocated with malloc(10 sizeof(int)). Which subtraction is defined?
- A linked list of length n is reversed in place with a loop. How much extra memory is used?
- unsigned int h = 0; for (const char p = "ab"; p; p++) h = h 31 + p; printf("%u", h); What is printed (ASCII, 32-bit unsigned)?
- unsigned int x = 0b11011010; printf("%u", (x >> 3) & 7); What is printed?
- With 32-bit unsigned arithmetic, what does (unsigned)-5 >> 1 print?
- What is the value of ~5 & 0xF in C, with int of 32 bits?