ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
typedef int (*Op)(int,int);
int a(int x,int y){ return x+y; }
int b(int x,int y){ return x-y; }
Op table[2] = {a, b};
int main(void) {
int r = table[1](table[0](3,4), 2);
printf("%d", r);
}- A. -1
- B. 9
- C. 1
- D. 5
Correct answer: D. 5
table[0](3,4) calls a(3,4)=7. table[1](7,2) calls b(7,2)=5.
More C Programming questions
- What is printed? c int a[2][3] = {{1,2,3},{4,5,6}}; int rowptrs[2] = {a[0], a[1]}; int pp = rowptrs; for (int i = 0; i < 2; i++) for (int…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers, natural alignment). What is printed? c struct Inner { char a; short b; }; struct…
- Assume unsigned int bitfields pack into 32-bit allocation units (typical gcc/Linux x86-64 behavior). What is printed? c struct BF {…
- Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is…
- On a little-endian 64-bit machine, what is printed? c union U { int i; char c[4]; }; union U u; u.i = 0x41424344; printf("%c%c%c%c"…
- Assume a 64-bit LP64 ABI. What is printed? c struct Variant { int type; union { int i; float f; double d; }; }; printf("%zu"…