ProgrammingHardProduct-company MCQ pattern
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int a[5];
printf("%td %td", (char *)(a + 1) - (char *)a,
(char *)(&a + 1) - (char *)a);- A. 20 20
- B. 4 20
- C. 1 5
- D. 4 4
Correct answer: B. 4 20
a decays to int *, so a + 1 is one int (4 bytes) further. &a has type int (*)[5], a pointer to the whole array, so &a + 1 is 5 × 4 = 20 bytes further. Same address, different types.
More C Programming questions
- What is printed? c printf("%d", 010 + 0x10 + 10);
- What happens? c for (unsigned int i = 3; i >= 0; i--) printf("%u ", i);
- What is printed? c char s[] = "abc0def"; printf("%zu %zu", sizeof(s), strlen(s));
- What is printed? c printf("%zu", strlen("atbn"));
- What is printed? c int a = -1, b = 1; if (a > 0) if (b > 0) printf("X"); else printf("Y"); printf("Z");
- What is printed? c int x = 4; if (x & 1 == 0) printf("even"); else printf("odd");