I encountered a written test topic of a company

xiaoxiao2021-03-06  113

The following is the written test topic I have encountered in a company interview. These topics are found on a person named stinky. It is amazed. I don't know if this stinking stub is with my interview. There is no relationship. The topic is exactly the same:

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) is pushed.

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) dosomething (); elsedootHering ();} // Second IF (condition) {for (i = 0; idosomething ();} else {for (i = 0; i dootherhes ();} Advantages: Disadvantages: Advantages: Disadvantages:

4. Thoughts on memory (20 points)

Void getMemory (char *) {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"; returnom p;} void test (void) {char * str = null; str = getMemory (); printf (str);}, please ask the Test function What kind of results? answer:

Void getMemory (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); struct (str); free (str); if (str! = Null) {structure (str, "world" PRINTF (STR);}} What kind of results will there be a Test function? answer:

5. Writing a strcpy function (10 points) 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?

Sixth, write String constructor, destructor and assignment function (25 points) Known String prototype: 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 string}; please Write the above four functions of String.

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

New Post(0)