ProgrammingHardTCS NQT · Infosys
int a[] = {2, 4, 6, 8}; int *p = a + 3, *q = a; What does printf("%td", p - q) print?
- A. 2
- B. 1
- C. 3
- D. 4
Correct answer: C. 3
Subtracting pointers into the same array gives the number of elements between them. p points to a[3] and q to a[0], so the difference is 3.
More C Programming questions
- char names[3][5] = {"ab", "cde", "f"}; What is strlen(names[1]) + sizeof names[2]?
- A recursive function sums decimal digits: int ds(int n) { return n < 10 ? n : n % 10 + ds(n / 10); }. What is ds(98765)?
- How many 1 bits does 0xDEADBEEF have in binary?
- uint32t value = (uint32t)-1; printf("%d", value == 0xFFFFFFFFu); What is printed?
- How many index pairs i < j in the array {3, 5, 3, 5, 7} satisfy a[i] XOR a[j] == 0?
- How many integers from 1 to 30 are multiples of 8?