ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
printf("%d %d %d", 5 > 3 && 2 > 4, !0, !!7);- A. 0 1 1
- B. 1 1 7
- C. 0 1 7
- D. 0 0 1
Correct answer: A. 0 1 1
Relational and logical operators in C produce int 0 or 1. 2 > 4 is false, so the && is 0. !0 is 1. !!7 first gives !7 = 0 and then !0 = 1 — the double negation normalises any non-zero value to 1, it does not return 7.
More C Programming questions
- What is printed? c int a = 5, b = 3; a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d", a, b);
- What is printed? c printf("%d %d %d", strcmp("abc", "abd") < 0, strcmp("ab", "abc") < 0, strncmp("abcx", "abcy", 3) == 0);
- What is printed? c int i = 3.99; int j = -3.99; int k = (int)(0.29 100); printf("%d %d %d", i, j, k);
- What is printed? c / 4-byte int with 4-byte alignment / struct S { int a; char b; } arr[5]; printf("%td %td", &arr[4] - &arr[1], (char…
- What is printed? c char s[] = "abcdef"; char p = s + 2; p[1] = 'X'; printf("%s %s %c %zu", s, p, (p - 2), strlen(p + 4));
- What is printed? c int f(int n) { if (n <= 0) return 0; return n % 2 ? f(n - 1) + n : f(n / 2) 2; } int main(void) { printf("%d %d"…