ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a = 10;
int *p = &a;
int *q = p;
p = NULL;
printf("%d %d", p == NULL, *q);- A. 0 0
- B. 1 10
- C. 0 10
- D. 1 0
Correct answer: B. 1 10
q was assigned a COPY of p's value (the address of a) before p was reassigned to NULL; pointers are ordinary values that get copied on assignment, so changing p afterward has no effect on q at all. p == NULL is true (1), and *q still correctly reaches a, 10.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int rows = 2, cols = 3; int matrix = malloc(rows sizeof(int )); for (int i = 0; i < rows…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 1; int p = &x; int pp = &p; int ppp = &pp; printf("%d", ppp == &pp && ppp == pp &&…
- 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…