ProgrammingHardProduct company OA

What is the type of the result of subtracting two int pointers, p - q?

  1. A. ptrdiff_t, a signed integer type defined in <stddef.h>
  2. B. size_t, because sizes are never negative
  3. C. int *, the same type as the operands
  4. D. unsigned int

Correct answer: A. ptrdiff_t, a signed integer type defined in <stddef.h>

Pointer subtraction gives the distance in elements as a signed ptrdiff_t, since q may be after p. It is printed with %td. size_t is what sizeof yields and is unsigned.

More C Programming questions

Exams that ask this topic