ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int x = 1;
int *p = &x;
int **pp = &p;
int ***ppp = &pp;
printf("%d", ppp == &pp && *ppp == pp && **ppp == p && ***ppp == x);- A. 0
- B. 1
- C. Undefined behaviour: comparing pointers at three levels
- D. Compile-time error
Correct answer: B. 1
Each level of indirection is exactly what it's declared to be: ppp genuinely holds &pp, *ppp genuinely equals pp, **ppp genuinely equals p, and ***ppp genuinely equals x (1). Every comparison in this chain is true, so the overall && expression is 1.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {10, 20, 30}; int b[3] = {10, 20, 30}; printf("%d %d", a == b, a == b);
- Assume a 64-bit LP64 ABI. What is printed? c int globalArr[5] = {1, 2, 3, 4, 5}; void resetArr(void) { for (int i = 0; i < 5; i++)…
- What is printed? c int main(void) { char c = 200; printf("%d", c); }
- What is printed? c int main(void) { int a = 10; int p = &a; int pp = &p; printf("%d %d %d", a, p, pp); a = 20; printf(" %d %d %d", a, p…
- What is printed? c enum Color { RED, GREEN, BLUE }; enum Color c = GREEN; printf("%d", c); enum Status { OK = 1, FAIL = 5, PENDING }…
- What is printed? c int main(void) { int x = 1; int p = &x; p += 1; (p)++; ++p; printf("%d", x); }