ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a = 100;
int *p = &a;
int *q = p;
p = NULL;
printf("%d %d", (p == NULL), (*q));- A. 1 0
- B. 0 100
- C. 0 0
- D. 1 100
Correct answer: D. 1 100
q was assigned a COPY of p's original value (the address of a) before p was reassigned to NULL; reassigning p doesn't affect q at all, since pointer variables are independent once copied. p==NULL is true (1); *q still correctly dereferences a, giving 100.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; void movePoint(struct Point p, int dx, int dy) { p->x += dx; p->y…
- Assume a 64-bit LP64 ABI. What happens? c int createArray(int n) { int arr[n]; for (int i = 0; i < n; i++) arr[i] = i i; return arr; } int…
- Assume a 64-bit LP64 ABI. What is printed? c int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; int sum = 0; for (int i = 0; i < 3; i++) sum +=…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 10; int p = &x; p = p p; printf("%d", x);
- Assume a 64-bit LP64 ABI. What is printed? c int a[5] = {1, 2, 3, 4, 5}; int start = a; int end = a + 5; int sum = 0; while (start != end)…
- Assume a 64-bit LP64 ABI. What is printed? c int f(int p) { p = 50; return p + 10; } int main(void) { int a = 5; int result = f(&a)…