ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int x = 10;
int *p = &x;
int **pp = &p;
**pp = 20;
*pp = NULL;
printf("%d %d", x, (p == NULL));- A. Compilation error
- B. 20 1
- C. 20 0
- D. 10 1
Correct answer: B. 20 1
**pp = 20 dereferences through pp to p to x, setting x to 20. *pp = NULL then assigns NULL directly to p itself (pp still points at p's storage), making p == NULL true, but x already holds 20 from the earlier assignment.
More C Programming questions
- What is printed? c void modify(int arr, int n) { for (int i = 0; i < n; i++) arr[i] = 2; } int main() { int a[] = {1, 2, 3}; int p = a…
- What is printed (64-bit, 4-byte int)? c int a[5] = {1,2,3,4,5}; int p = a + 5; printf("%d", (p - 1) + (a + 0));
- What is printed? c int x = 100; void f(int p) { int y = 200; p = &y; } int main() { int p = &x; f(p); printf("%d", p); }
- What is printed? c int arr[3] = {1, 2, 3}; int (p)[3] = &arr; printf("%d %d", (p)[1], (p + 2));
- What is printed (64-bit LP64)? c int a = 10; void vp = &a; int ip = (int )vp; char cp = (char )&a; printf("%d %zu %zu", ip, sizeof(vp)…
- What is printed? c int a = 5; int p = &a; int q = p; p = NULL; printf("%d %d", q, p == NULL);