The basic programming skills, programming quality of C ++C programmers, the programming quality, and the degree of understanding

zhaozj2021-02-08  215

The basic programming skills, programming quality of C / C programmers, the programming quality, and the degree of understanding of C / C

This test is only used to examine the basic programming skills of C / C programmers. The content is limited to C / C common grammar, does not involve data structures, algorithms, and deep syntax. The test scores reflect the quality of the programming and the degree of understanding of C / C, but can not reflect the intelligence and software development capabilities of candidates.

The written test time is 90 minutes.

First, please fill in the IF statement of BOOL, FLOAT, pointer variables and "zero" comparison. (10 points)

Tip: Here "zero" can be 0, 0.0, false, or "empty pointer". For example, INT variable N and "zero value" comparison IF statement is:

IF (n == 0)

IF (n! = 0)

Push it in this class.

Please write the IF statement of BOOL FLAG and "Zero" comparison:

Please write the IF statement of Float X and "Zero" comparison:

Please write the IF statement of char * p and "zero" comparison:

Second, the following is the 32-bit C program under Windows NT, calculate the value of SIZEOF (10 points)

Char str [] = "hello"; char * p = Str; int n = 10; calculates sizeof (STR) = sizeof (p) = sizeof (n) = void func (char STR [100]) {please calculate SIZEOF (STR) =}

Void * p = malloc (100); please calculate SizeOf (P) =

Third, a brief answer (25 points)

1. What is the use of IFNDEF / Define / Endif in the header file?

2, # include and #include "filename.h" What is the difference?

3, what is the use? (Please explain at least two)

4. Call the function after being compiled by the C program, why do you want to declare the extern "C"?

5. Please briefly describe the advantages and disadvantages of the following two for loops.

// First

For (i = 0; i

{

IF (condition)

DOSMETHING ();

Else

Doothershing ();

}

// the second

IF (condition)

{

For (i = 0; i

DOSMETHING ();

}

Else

{

For (i = 0; i

Doothershing ();

}

advantage:

Disadvantages:

advantage:

Disadvantages:

4. Thoughts on memory (20 points)

Void getMemory (char * p)

{

P = (char *) malloc (100);

}

Void test (void) {char * str = NULL;

GetMemory (STR);

STRCPY (STR, "Hello World");

Printf (STR);

}

What kind of results will there be a Test function?

answer:

Char * getMemory (void)

{

Char p [] = "Hello World"; Return P;

}

Void test (void)

{

CHAR * STR = NULL;

Str = getMemory ();

Printf (STR);

}

What kind of results will there be a Test function?

A: Void getMemory2 (char ** p, int Num)

{

* p = (char *) Malloc (NUM);

} void test (void)

{

CHAR * STR = NULL;

GetMemory (& STR, 100);

STRCPY (STR, "Hello");

Printf (STR);

} What kind of results will there be a Test function?

answer:

Void test (void)

{

Char * str = (char *) malloc (100);

STRCPY (STR, "Hello");

Free (STR);

IF (str! = null)

{

STRCPY (STR, "world");

Printf (STR);

}

} What kind of results will there be a Test function?

answer:

Five, write strcpy functions (10 points)

Know the prototype of the STRCPY function is

Char * STRDEST, Const Char * strsrc);

STRDEST is the destination string, and strsrc is a source string.

(1) Do not adjust the C / C string library function, please write the function strcpy

(2) STRCPY can copy the contents of strsrc to strDest, why should the return value of the type?

6. Write the constructor, destructor and assignment function (25 points)

The prototype of the known String is:

Class String

{

PUBLIC:

String (const char * str = null); // ordinary constructor

String (const string & other); // Copy constructor

~ String (void); // Destructor

String & Operate = (const string & other); // assignment function

Private:

Char * m_data; // Used to save strings

}

Please write the above four functions of String.

转载请注明原文地址:https://www.9cbs.com/read-3359.html

New Post(0)