ProgrammingVery hardCapgemini · C · Advanced
What is printed?
What is printed?
int add(int a, int b) { return a + b; }
int sub(int a, int b) { return a - b; }
int mul(int a, int b) { return a * b; }
int main(void) {
int (*op[])(int, int) = {add, sub, mul};
int r = 6;
for (int i = 0; i < 3; i++) r = op[i](r, i + 2);
printf("%d", r);
return 0;
}- A. 20
- B. 18
- C. 24
- D. 30
Correct answer: A. 20
add(6,2) = 8, sub(8,3) = 5, mul(5,4) = 20.
More C Programming questions
- What is printed? c struct N { int v; struct N nx; }; int main(void) { struct N c = {3, 0}, b = {2, &c}, a = {1, &b}; struct N p = &a…
- What is printed? Assume C99 or later. c int g(int a, int b) { return b ? g(b, a % b) : a; } int main(void) { printf("%d %d", g(-48, 18)…
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main(void) { int i = 3, j = 1; int m = MAX(i++, j++); printf("%d %d %d"…
- In C, sizeof(char) is:
- Which storage class makes a local variable keep its value between calls to the function?
- The end of a C string is marked by: