C#include <stdio.h> int main { unsigned int x = 5; int y = -10; if (x + y > 0) { printf("Positive\n"); } else { printf("Negative\n"); } return 0;}What is the output of this code?
Correct answer: A. Positive
- A. Positive
- B. Negative
- C. Compiler warning
- D. Undefined behavior
Explanation
x + y involves an unsigned and a signed integer. The signed integer is implicitly converted to unsigned.-10 when represented in unsigned form becomes a very large positive value due to two's complement representation, making the result of x + y positive
Report an error
The more specific you are, the faster it gets fixed. A source beats an opinion.
Prefer email? [email protected]
About Programming Basics
Programming basics covers algorithms, flowcharts, pseudocode, variables, constants, data types, operators, input and output, conditional statements and loops. It also introduces functions, arrays, strings, debugging and common programming errors, with attention to the difference between syntax errors, runtime errors and logical errors in a program.
Practise Programming Basics
183 free Programming Basics MCQs from Computer Science and IT, each with the correct answer and an explanation. Unlimited attempts, no account needed.
Discussion
Stuck on an option, or know a faster way to get there? Ask or explain it here.
No comments yet. Be the first to explain this one.
Exams that ask Computer Science and IT questions like this
Computer Science and IT is on 85 papers prepared for on TestUstad, and all of them draw the same bank, so this question is worth knowing for every one of them.
More Programming Basics questions
C#include <stdio.h>int main { int x = 10; float y = 3.5; double z; z = x / y; printf("%.2f\n", z); return 0;}What is the output of this code?
C#include <stdio.h> int main { short int s = 32767; s = s + 1; printf("%d\n", s); return 0;}What is the output of this code?
C#include <stdio.h> int main { float f = 3.14; int i = (int) f; char c = (char) i; printf("f = %.2f, i = %d, c = %c\n", f, i, c); return 0;}What is the output of this code?
C#include <stdio.h> int main { int x = 5; float y = (float) x / 2; printf("%.2f\n", y); return 0;}What is the output of this code?
C#include <stdio.h> int main { int a = 5, b = 5; int result = --a - b--; printf("a = %d, b = %d, result = %d\n", a, b, result);}What is the output of this code?
C#include <stdio.h> int main { int x = 10; int y = --x - x--; printf("x = %d, y = %d\n", x, y); return 0;}What is the output of this code?