ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
#define SQ(x) x * x
int main(void) {
int i = 3;
printf("%d", SQ(i + 1));
}- A. 16
- B. 9
- C. 10
- D. 7
Correct answer: D. 7
The macro substitutes the text, giving i + 1 * i + 1 = 3 + 3 + 1 = 7. Parenthesising the parameter as ((x) * (x)) gives 16.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int c = 0; for (unsigned x = 0; x < 256; x++) if ((x & (x >> 1)) == 0) c++…
- What is printed? c #include <stdio.h> int main(void) { const char s[] = {"ab", "cde", "f"}; printf("%c%c", s[2], s[1][2]); }
- What is printed? c #include <stdio.h> int main(void) { unsigned x[] = {4000000000u, 4000000000u, 4000000000u}; unsigned s = 0; for (int i…
- What is printed? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0, j = 10; i < j; i += 2, j--) c++; printf("%d", c); }
- char b[5]; int n = snprintf(b, sizeof b, "%s", "abcdefgh"); printf("%s %d", b, n); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); printf("%d %s", n, buf); What is printed?