C Language test questions (standard answer)

Source: Internet
Author: User
Tags function prototype

C Language test questions (standard answer)

I. Single topic (2 points per quiz, total 20 minor 40 points)

1.1-1.5 B D a c b 1.6-1.10 c a D b C

1.11-1.15 A D d C b 1.16-1.20 d a b c a

Two. Fill in the blanks (2 points each, total 10 empty 20 minutes)

2.1 52.

2.2 10; 12; 120.

2.3 110.

2.4 0x801005; 0x801014.

2.5 2; 5.

2.6 Automatic.

Three. Short answer (4 points per question, total 5 20 points)

3.1 Global variables can be defined in multiple . C file included in the header file? Why?

Answer: Yes. (2 points)

Declare a global variable with the same name in static form in a different C file . (2 points)

What is the difference between a 3.2 reference and a pointer?

A:(1) The reference must be initialized, the pointer does not have to be; (1 points)

(2) after the reference initialization cannot be changed, the pointer can change the object referred to; (1.5 points)

(3) There is no reference to a null value, but there is a pointer to a null value. (1.5 points)

What is the cause of the 3.3 stack overflow?

A: There is no recycling of garbage resources. (or a: No useless resources are released.) ) (4 points)

What is the difference between a 3.4 queue and a stack?

A: Queue FIFO First, (2 points) stack LIFO. (2 points)

3.5 Compile the workspace, often encounter error code "0x00000002" Compile error, find the corresponding error description but not found, what is the reason for this situation? What should be done?

A: The reason is that the compilation process produced unpredictable errors. (2 points)

The workaround is to attempt to restart the computer or disable distributed compilation with a single machine compilation. (2 points)

Four. Programming questions (10 points for each small question, 2 items in 20 points)

4.1 writes a function that implements an inverse output of an integer that is represented by a parameter n , such as n=1234, that outputs 4321, no C Library functions are required and the function prototype is as follows:void inv (int n);

Answer scoring criteria:

1, consider the situation of negative numbers:3 points

2, the use of temporary variables:2 points

3, print and print the correct format:1 points

4, there are corresponding comments:1 points

5. The result is completely correct:3 points

Reference program:

void Inv (int n)

{

int tmpnum = n; temporary variable used:2 points

if (Tmpnum < 0)// Considering negative numbers:3 points

{

Negative number

k = 0;

Tmpnum =-tmpnum;

printf ("-");

}

while (Tmpnum)

{

printf ("%d", tmpnum%10); printed correctly:1 points

Tmpnum = TMPNUM/10;

}

}

4.2 2~2000 all primes and prints on the screen with enough memory to be as fast as possible.

Answer scoring criteria:

1. Save the found prime, use global array and global variables instead of temporary application space:3 points

2. Critical cycle of judging primes:3 points

3, print and print the correct format:1 points

4, there are corresponding comments:1 points

5. The result is completely correct:2 points

Reference program:

int findvalue[2000] = {2}; Global array and global variables are used:3 points

static int find = 1;

BOOL Adjust (int value);

void Getprimenumbers (void)

{

for (int i = 2; I <=; i++)

{

if (adjust (i))// have print judgment and print the statement correctly:1 points

{

printf ("%d", I);

}

}

}

BOOL Adjust (int value)

{

ASSERT (value>=2);

if (value = = 2)

{

return true;

}

for (int i = 0; i < find; i++)// critical cycle of judging primes:3 points

{

if (value% findvalue[i] = = 0)

{

return false;

}

}

findvalue[find++] = value;

return true;

}

C Language test questions (standard answer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.