ProgrammingHardProduct company OA

Assume a 64-bit ABI with 4-byte int. What is printed?

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

Correct answer: A. 4 1

Pointer arithmetic scales by the pointee's size: int* advances by sizeof(int)=4 bytes, char* advances by sizeof(char)=1 byte.

More C Programming questions

Exams that ask this topic