ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int a[2][3] = {{1,2,3},{4,5,6}};
int *p = &a[0][0];
printf("%d ", *(p + 4));
int (*rows)[3] = a;
printf("%d", (*(rows + 1))[1]);- A. 5 5
- B. 4 5
- C. 4 4
- D. 5 4
Correct answer: A. 5 5
p walks the array flattened, so p+4 is the 5th element overall: a[1][1] = 5. rows points at whole rows; *(rows+1) is row 1, and [1] of that is a[1][1] = 5. Both expressions reach the same element.
More C Programming questions
- What is printed? c int global = 100; int getGlobal() { return &global; } int main() { int p = getGlobal(); p = 200; printf("%d %d"…
- What is printed? c void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int x = 1, y = 2; int p = &x, q = &y; swap(&p…
- Assume 64-bit LP64, natural alignment. What is printed? c struct A { int i; char c; }; struct B { char c; int i; }; printf("%zu %zu"…
- Assume 64-bit LP64, natural alignment. What is printed? c struct S { double d; int i; }; struct S arr[3]; printf("%zu %zu", sizeof(struct…
- Assume 64-bit LP64. What is printed? c struct Node { int val; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume 64-bit LP64, natural alignment, and #pragma pack(1) applied. What is printed? c #pragma pack(1) struct Packed { char c; int i; char…