C#include <stdio.h> int main { char ch = 128; printf("%d\n", ch); return 0;}What is the likely output of this code?
Correct answer: B. -128
- A. 128
- B. -128
- C. 0
- D. A compiler warning or error
Explanation
The char type is usually signed, with a range of -128 to 127.Assigning 128 to a signed char causes an overflow, wrapping around to the minimum representable value
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>#include <limits.h> int main { unsigned short int x = USHRT_MAX; // Maximum value of unsigned short x = x + 2; printf("%d\n", x); return 0;}What is the output of this code?
C#include <stdio.h> int main { int x = 2; int y = 2 * x++ + 3 * ++x; printf("x = %d, y = %d\n", x, y); return 0;} What is the output of this code?
C#include <stdio.h> int main { int a = 10, b = 5; int result = a++ / --b; printf("a = %d, b = %d, result = %d\n", a, b, result); return 0;} What is the output of this code?
C#include <stdio.h> int main { int x = 2, y = 4; int z = x-- && --y; printf("x = %d, y = %d, z = %d\n", x, y, z); return 0;}What is the output of this code?
C#include <stdio.h> int main { int a = 10, b = -5; int x = --a - b--; printf("a = %d, b = %d, x = %d\n", a, b, x); return 0;}What is the output of this code?
C#include <stdio.h> int main { int x = 10; while (x--) { if (x == 5) { x -= 2; } printf("%d ", x); } return 0;} What is the output of this code?