C Language Exercise Class – Day 18

01

C Language Exercise Class - Day 18

(Multiple Choice) To define a one-dimensional array a with 10 int elements, the following definition statements arecorrect:

A) #define N 10

int a[N];

B) #define n 5

int a [2*n];

C) int a[5+5];

D) int n=10,a[n];

C Language Exercise Class - Day 18

Answer: ABC

Explanation:

For option D: In the C89 standard, the size of an array must be a constant expression, not a variable.

02

C Language Exercise Class - Day 18

(Multiple Choice) The number systems that can be represented in C language source programs are

A) Binary

B) Octal

C) Decimal

D) Hexadecimal

C Language Exercise Class - Day 18

Answer: BCD

Explanation:

For option A: Traditional C language (C89) does not support direct binary representation and requires manual conversion.

For option B: C language supports it, using the 0 prefix:

For option C: Directly writing numbers without a prefix:

For option D: C language supports it, using 0x or 0X prefix:

03

C Language Exercise Class - Day 18

(Multiple Choice) According to the naming rules for user identifiers in C language, the following can appear in identifiers:

A) Uppercase letters

B) Connectors

C) Digits

D) Underscores

C Language Exercise Class - Day 18

Answer: ACD

Explanation: Brief

04

C Language Exercise Class - Day 18

(Multiple Choice) The followingillegal character constants are ( )

A) ‘\x13’

B) ‘\081’

C) ‘\065’

D) “\n”

C Language Exercise Class - Day 18

Answer: BD

Explanation:

For option A: ‘\x13’ is a valid hexadecimal escape sequence;

For option B: ‘\081’ seems to be an octal escape sequence (\ followed by 1-3 octal digits), but the octal digit range is 0-7, and 8 is an illegal character;

For option C: ‘\065’ is a valid octal escape sequence;

For option D: “\n” is a string constant (enclosed in double quotes), not a character constant;

05 (Common Mistake)

C Language Exercise Class - Day 18

(Multiple Choice) The followingvalid character constants are

A) ‘\018’

B) ‘”‘

C) ‘\\’

D) ‘\0xcc’

C Language Exercise Class - Day 18

Answer: BC

Explanation:

For option A: Single quotes ” indicate character constants, not string constants;

For option B: The representation method for escaped characters in double quotes. Note: The representation method for escaped characters in single quotes is ‘\”, and the representation method for escaped question mark is ‘\?’

For option C: The representation method for the backslash;

For option D: ‘\0xcc’ is also illegal because \0xcc is not a valid escape sequence (hexadecimal escape should be \xcc);

06

C Language Exercise Class - Day 18

(Multiple Choice) The following statements arecorrect:

A) C statements must end with a semicolon

B) Compound statements are syntactically considered a single statement

C) Empty statements do not affect program execution regardless of their position

D) Adding a semicolon at the end of an assignment expression constitutes an assignment statement

C Language Exercise Class - Day 18

Answer: ABD

Explanation:

For option C: An empty statement (just a semicolon 😉 may lead to logical errors in certain positions.

07 (Common Mistake)

C Language Exercise Class - Day 18

(Multiple Choice) The followingvalid assignment statements are

A) n=(i=2,++i);

B) j==1;

C) ++(i+1);

D) x=j>0;

C Language Exercise Class - Day 18

Answer: AD

Explanation:

For option B: This is a relational expression (checking if j equals 1), not an assignment statement;

For option C: The increment operator ++ must have a modifiable lvalue (like a variable) as its operand; i+1 is a temporary computed result, not a modifiable lvalue;

08

C Language Exercise Class - Day 18

(Multiple Choice) The following cancorrectly define a two-dimensional array:

A) int a[2][2] = {{1}, {2}};

B) int a[ ][2] = {1, 2, 3, 4};

C) int a[2][2] = {{1}, {2},{3}};

D) int a[2][ ] = {{1, 2}, {3, 4}};

C Language Exercise Class - Day 18

Answer: AB

Explanation:

For option C: Defined a 2×2 array but provided 3 rows of initialization data ({1}, {2}, {3});

For option D: When defining a two-dimensional array, note that the number of columns cannot be omitted; in C language, the number of rows can be omitted, but the number of columns must not be omitted;

09

C Language Exercise Class - Day 18

(Multiple Choice) If there is a definition: int a[8]; then the following expressions that can represent the address of array element a[1] are

A) &a[0]+1

B) &a[1]

C) &a[0]++

D) a+1

C Language Exercise Class - Day 18

Answer: ABD

Explanation: Brief

10

C Language Exercise Class - Day 18

(Multiple Choice) Given the definition: int i,a[10],*p; , the followingillegal assignment statements are

A) p=100;

B) p=a[5]

C) p=&a[2]+2

D) p=a+2;

C Language Exercise Class - Day 18

Answer: AB

Explanation: Brief

Leave a Comment