ProgrammingHardTCS NQT · Infosys
int a[5]; int *p = &a[4]; printf("%td", p - &a[0]); What is printed?
- A. 5
- B. 4
- C. 3
- D. 0
Correct answer: B. 4
&a[4] minus &a[0] is the element distance 4. An off-by-one reading would print 5, the array length.
More C Programming questions
- What does printf("%d", '7' - '0' == 7) print?
- Reversing the list 1 -> 2 -> 3 -> 4 -> 5 in place with the usual three-pointer loop, what are head->v and head->next->v afterwards?
- In a list 1 -> 2 -> 3 -> 4 -> 2 where the last node points back to the node holding 2, Floyd's method runs slow = slow->next and fast =…
- A pointer-to-pointer loop deletes every node holding 2 from 2 -> 2 -> 3 -> 2 -> 1, using struct N pp = &head and advancing only when no…
- Which code correctly removes node p from a doubly linked list, where p->prev and p->next may be NULL, and then frees it?
- Merging two sorted singly linked lists of length 3 each with the standard merge, what is the largest number of key comparisons needed?