ProgrammingHardProduct company OA

Assume a 4-byte int. What is printed?

Assume a 4-byte int. What is printed?
#include <stdio.h>
int main(void) {
    int a[2][3];
    int (*p)[3] = a;
    p++;
    printf("%ld", (long)p - (long)a);
}
  1. A. 12
  2. B. 3
  3. C. 4
  4. D. 24

Correct answer: A. 12

p is a pointer to a row of 3 ints, so p++ advances it by one whole row: 3 * sizeof(int) = 12 bytes.

More C Programming questions

Exams that ask this topic