ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a[3] = {10, 20, 30};
int b[3] = {10, 20, 30};
printf("%d %d", a == b, *a == *b);- A. 1 1
- B. 0 1
- C. 1 0
- D. 0 0
Correct answer: B. 0 1
a and b are two separate arrays with identical contents but different memory locations; when used in this context, both decay to pointers to their own first elements, which are different addresses, so a == b (comparing addresses) is 0. *a and *b dereference to compare the actual VALUES stored (both 10), which are equal, giving 1.
More C Programming questions
- 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); }
- What is printed? c int main(void) { int x = 0; int y = (x = 5, x + 1); printf("%d %d", x, y); }