ProgrammingVery hardTCS NQT · C · Advanced
What is printed? Assume C99 or later.
What is printed? Assume C99 or later.
int g(int a, int b) { return b ? g(b, a % b) : a; }
int main(void) {
printf("%d %d", g(-48, 18), g(48, -18));
return 0;
}- A. 6 -6
- B. 6 6
- C. -6 -6
- D. -6 6
Correct answer: A. 6 -6
From C99 the sign of % follows the dividend: g(-48,18) -> g(18,-12) -> g(-12,6) -> g(6,0) = 6; g(48,-18) -> g(-18,12) -> g(12,-6) -> g(-6,0) = -6.
More C Programming questions
- 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:
- Which declaration makes p a pointer to an int?
- A line such as #include <stdio.h> is processed by: