ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int a = 10;
int *p = &a;
int *q = p;
p = NULL;
printf("%d", *q);- A. 0
- B. Undefined behavior: p is NULL
- C. 10
- D. Compilation error
Correct answer: C. 10
q was assigned a COPY of p's value (the address of a) before p was set to NULL; q still holds &a, which is perfectly valid, so *q reads a = 10. Setting p to NULL does not retroactively affect q.
More C Programming questions
- What is printed? c int f(int n) { if (n == 0) return 0; return n + f(n - 1); } int main(void) { printf("%d", f(4)); }
- What is printed? c int fib(int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } int main(void) { printf("%d", fib(6)); }
- What is printed? c int f(int n) { if (n == 0) return 0; printf("%d ", n); if (n % 2 == 0) return f(n / 2); return f(n - 1); } int…
- How many TOTAL calls to fib (including the initial call) are made evaluating fib(4), given this naive recursive implementation? c int…
- What is printed? (recursion where the recursive call's result is deliberately ignored) c int calls = 0; int f(int n) { calls++; if (n <=…
- What is printed? (recursion depth vs. the array being modified on the way back up) c int a[5] = {1, 2, 3, 4, 5}; void f(int i) { if (i >=…