Basic Knowledge
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem 1. Basic knowledge
- Select the correct statement(s).
{{ multiselect(1) }}
- We can setup our own IDE (Integrated Development Environment) by having VSCode configured with some extensions, compilers and debuggers.
- C++23 is the latest C++ standard released in 2023. If we want to write code in C++23, we should upgrade VSCode to the latest version.
- GCC can only support Windows. In Linux, we must use Clang.
- A C program can be executed directly by the computer without being transformed into an executable file.
- We can compile and run C/C++ programs in the terminal.
- VSCode and CLion are different types of C/C++ compilers.
- Fill in the blanks. For the column "Signedness", write either
signedorunsigned. If the answer to any of the blanks is implementation-defined, writeid.
| Type | Signedness | Number of bits at least |
|---|---|---|
char |
{{ input(2011) }} | {{ input(2012) }} |
signed char |
{{ input(2021) }} | {{ input(2022) }} |
unsigned char |
{{ input(2031) }} | {{ input(2032) }} |
short |
{{ input(2041) }} | {{ input(2042) }} |
unsigned |
{{ input(2051) }} | {{ input(2052) }} |
int |
{{ input(2061) }} | {{ input(2062) }} |
long |
{{ input(2071) }} | {{ input(2072) }} |
long long |
{{ input(2081) }} | {{ input(2082) }} |
- Suppose
intis 32-bit. Suppose we have the following variable declarations.
int ival = 45;
double dval = 3.14;
unsigned uval = -5;
Write down the type and the value of each of the expressions in the following table. If the type is floating-point, round the value to 2 decimal places. If a type has more than one names, write the shortest one, e.g. write int for signed int.
| Expression | Type | Value |
|---|---|---|
ival + dval |
{{ input(3011) }} | {{ input(3012) }} |
uval |
{{ input(3021) }} | {{ input(3022) }} |
ival * ival |
{{ input(3031) }} | {{ input(3032) }} |
ival / 2.0 |
{{ input(3041) }} | {{ input(3042) }} |
-100 / ival |
{{ input(3051) }} | {{ input(3052) }} |
- Suppose
cis a variable of typechar. Ifcis a decimal digit character, how can we obtain its numeric value?
{{ multiselect(4) }}
c - '\0'c - '0'int(c)c - 0c - 48ord(c) - '0', whereordis a standard library function that is used to obtain the ASCII value ofc.
- Regarding undefined behaviors, which of the following statements is/are true?
{{ multiselect(5) }}
-
An undefined behavior means that two or more behaviors are permitted by the standard and that the compiler will choose a meaningful one. The behavior remains unchanged when the program is run again, although we don't know what the behavior is.
-
An undefined behavior means that program calls to undeclared or undefined functions.
-
An undefined behavior means that there are no restrictions on the behavior of the program. The standard does not require such programs to do anything meaningful.
-
An undefined behavior results in one of a set of valid results. For example, the following code (assuming
intis 32-bit) will assign the variablexwith some value, but we don't know what the value is.int ival = 10000000; int x = ival * ival; -
Correct C programs shall not have undefined behaviors.
- Suppose
intis 32-bit andlong longis 64-bit. Select the code snippet(s) that involve(s) integer overflow.
{{ multiselect(6) }}
-
unsigned u1 = 10000001; u1 = u1*u1*u1*u1*u1; -
int inf = 42 / 0; -
long long ival = -1000000000000000; unsigned uval = ival; -
int ival = 10000000; long long llval = ival * ival;
- Suppose
intis 32-bit. Select the code snippet(s) that involve(s) undefined behavior.
{{ multiselect(7) }}
-
unsigned uval = -111; printf("%u%%\n", uval); -
int x = 96; printf("%f\n", x/100); -
int i = 42; printf("%d%d\n", ++i, i); -
int helper(int value) { printf("value is %d\n", value); } int main(void) { int x = helper(42); int y = helper(x); printf("%d\n", x + y); } -
int random(void) { int x; return x; } int main(void) { printf("%d\n", random()); } -
double lim(int condition, double formula){ double d = 0.000618, dx = 1.0; return condition ? 0 : d*formula/dx; } int main(void){ int _x = 1, x = 4399, inf = 2147483647; double e = lim(_x --> inf, (1 + 1/x)^x); }