ProgrammingHardGATE CS · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
int (*p)[3] = m;
int *q = (int *)p + 4;
printf("%d", *q);
}- A. 3
- B. 4
- C. 6
- D. 5
Correct answer: D. 5
A 2D array is stored row by row, so flat index 4 is element m[1][1] = 5. Index 4 is not the end of a row, so the answer is not 6.
More C Programming questions
- What is printed? Assume unsigned short is 16 bits. c #include <stdio.h> int main(void) { unsigned short y = 60000; y += 10000…
- What is printed? c #include <stdio.h> void gen(int d, int v) { if (d == 0) { printf("%d ", v); return; } gen(d - 1, v 2 + 1); gen(d - 1, v…
- What is printed? c #include <stdio.h> unsigned inv(unsigned g) { unsigned n = 0; for (; g; g >>= 1) n ^= g; return n; } int main(void) {…
- What is printed? c #include <stdio.h> int main(void) { int dp[16] = {0}; int sum = 0; for (int i = 1; i < 16; i++) dp[i] = dp[i >> 1] + (i…
- Assume int is 4 bytes with 4-byte alignment and char is 1 byte. What is printed? c #include <stdio.h> struct A { char c; int i; char d; }…
- How many subsets of {1, 2, 3, 4} (the empty set included) have an XOR of zero? c #include <stdio.h> int main(void) { int count = 0; for…