ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int main(void) {
int x = 5, y = 5;
if (x = y)
printf("true:%d", x);
else
printf("false:%d", x);
}- A. false:5
- B. Compilation error: assignment in condition is not allowed
- C. true:1
- D. true:5
Correct answer: D. true:5
`x = y` is an ASSIGNMENT (not a comparison, a classic = vs == typo trap), which assigns 5 to x and evaluates to that value, 5, which is truthy; the if-branch runs, and x is still 5, so "true:5" prints.
More C Programming questions
- What is printed? c int main(void) { int a = 2, b = 3; int result = a++ b-- + --a + ++b; printf("%d %d %d", a, b, result); }
- What is printed? c int main(void) { int n = 4; int triangle = n (n + 1) / 2; printf("%d", triangle); }
- What is printed? c int main(void) { int x = 15; int y = 4; printf("%d %d %d", x / y, x % y, (x / y) y + (x % y)); }
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…