2020 diamond C + + C learning notes (2) — erudite Valley

Time:2021-12-3

Diamond C + + C in 2020 — erudite Valley

1.The legal names in the following identifiers areA

 

A、__A__

B、ab.c

C、@rp

D、2Y_

2.set upIf both a and B are double variables, and a = 5.5 and B = 2.5, the value of expression (int) a + B / B isD

 

A、6.500000

B、6

C、5.500000

D、6.000000

3.The basic data types in C language includeD

 

A. Integer, floating point, character, logical, enumeration

B. Integer, floating point, character, enumeration

C. Integer, floating point, character, logical

D. Integer, floating point, character

4.OneThe execution of C program is generally fromA

 

A. The main() function of this program starts and ends with the main() function

B. The first function of this program file starts and ends with the last function of this program file

C. The main () function of this program starts and ends with the last function of this program file

D. The first function of this program file starts and ends with the main() function of this program

5.For two character arraysA and B initialize char a [] = “ABCDEF”; char b[]={‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’}; Then the following statement is correctD

 

A. A and B arrays are identical

B. The array size of a and B is the same

C. Both a and B store strings

D. Array A is longer than array B

6.If definedint a[3][4] = { 0 }; Illegal reference to a array element isB

 

A、a[0][2*1]

B、a[1][4]

C、a[4-2][0]

D、a[2][3]

7.The following incorrect string constants areA

 

A、’abc’

B、”12’12”

C、”0″

D、” “

8.Conditional structure statements nested in multiple layersIn if else, the else clause is always associated with(  B)Pairing

 

A. The nearest unpaired if

B. Its previous nearest unpaired if

C. The nearest unpaired if after it

D. Unpaired if on the same line

9.x. Y and Z are defined as int variables. If you input data to x, y and z from the keyboard, the correct input statement isB

 

A、printf(“%d%d%d”, &x, &y, &z);

B、scanf(“%d%d%d”, &x, &y, &z);

C、scanf(“%d%d%d”, x, y, z);

D、printf(“%d%d%d”, x, y, z);

10.set upint x = 1, y = 1; The value of the expression (! X | Y –) isB

 

A、0

B、1

C、2

D、-1

11.If variableA has been correctly defined. The following illegal expression isB

 

A、a /= b + c

B、a % (4.0)

C、a = 1 / 2 * ( x = y = 20, x * 3)

D、a = b = c

12.If there is an array definitionint a[] = {1,3,5,4,9,2,7,6,8,10}; int i = 4; Then the value of the a [a [i]] element is equal toD

 

A、4

B、9

C、8

D、10

13.programchar c[5] = {‘a’, ‘b’, ‘\0’, ‘c’, ‘\0’};   printf(“%s”, c); The result of the operation isB

 

A、’a”b’

B、ab

C、ab c

D、ab0c0

14.Judgment stringIf a is greater than B, it should be usedD

 

A、if (a > b)

B、if (strcmp(a, b))

C、if (strcmp(b, a) > 0)

D、if (strcmp(a, b) > 0)

15.If the statement is executedfor(int a = 0, b = 0; b != 100 && a < 5; a++) scanf(“%d”, &b); Then the scanf () function performs the least(  D)Times

 

A、0

B、6

C、5

D、1

16.Express relationshipThe C language expression of 12 < = x < = y isB

 

A、(12 <= x <= y)

B、(12 <= x) && (x <= y)

C、(12 <= x) <= y)

D、(12 <= x) || (x <= y)

17.Use statementscanf(“a=%s,b=%d”, &a, &b); When entering data, the correct data input isA

 

A、a=2.2,b=3

B、a=2.2 b=3

C、2.2 3

D、2.2,3

18.The following description of operator precedence is correctC

 

A. Relational operator < arithmetic operator < assignment operator < logical and operator

B. Logical and operators < relational operators < arithmetic operators < assignment operators

C. Assignment operator < logical and operator < relational operator < arithmetic operator

D. Arithmetic operator < relational operator < assignment operator < logical and operator

19.ifint x=0, y=3, z=3; The value of the following expression is 0C

 

A、!x

B、 x < y ? 1 : 0

C、x / 2 && y != z

D、y = x || z % 2

20.

The output of the following procedure is( C    )

           #include

 

                       int main(void)

           {

               int a = 7 ,b = 5;

                 printf(“%d\n”,b=b/a)

               return 0 ;

           }

 

 

A、5

B、1

C、0

D. Uncertain

 

Short answer

21.sketchThe compilation process of C language program and the object file generated at each stage4 points

Reference answer:

1)Preprocessing: macro definition expansion, header file expansion, conditional compilation, etc., and delete comments in the code. Syntax will not be checked here

2)Compile: check the syntax and compile the preprocessed file to generate an assembly file

3)Assembly: generates an assembly file into an object file(Binary file)

4)Link:CPrograms written in language need to rely on various libraries, so after compilation, you need to link the library to the final executable program

 

22.sketchNaming rules for C language identifiers3 points

 

Reference answer:

1An identifier used to identify the name of an object in the source program,An identifier consists of letters, numbers, and underscores

2Keywords can define variables, express statement functions and preprocess some files. Keywords have been used by the compilation system itself, so users cannot use these keywords as identifiers when writing programs,

 

 

23.Is the character array the same as the string? If not, what is the difference?3 points

Reference answer: different,CThere are no special string variables in the language,If you want to store a string in a variable,You must use a character array,That is, a character array is used to store a string,Each element in the array holds one character. String: must be in‘\0’Ending character array: can contain multiple characters‘\0’

 

24.What are the characteristics of parameter passing in C language? What should we pay attention to?3 points

Reference answer:

1)Value transfer: the operation of formal parameters in the called function does not affect the actual parameter value in the calling function. 
2)Address passing: the actual parameter value in the calling function can be modified through the operation on the formal parameter in the called function.

Precautions: usemalloc After applying for memory, you should immediately check whether the pointer value isNULL。 Prevent the use of pointer valuesNULL Memory.

 

25.What is the relationship between pointer and address? What details should you pay attention to when using pointers? What is the significance of pointer type for programming?3 points

Reference answer:

1)The pointer holds the address of a variable, and the pointer itself is a variable,It also has its own addressThe content of the pointer is the address of a variable. Attention to details: initialization, correct address delivery method and judgment during use.

2)Pointers can be used to effectively represent complex data structures,It can be used to pass function parameters and achieve the purpose of using functions more flexibly.sendCThe design of language program is flexible, practical and efficient.