1. Write and judge whether the four expressions of ABCD are correct. If so, write the value of A in the expression (3 points)
Int A = 4;
(A) A ++ = (a ++); (B) a ++ = (++ A); (c) (a ++) ++ = A; (d) (++ A) ++ = (a ++ );
A =?
A: C error. The left side is not a valid variable and cannot be assigned a value. You can change it to (++ A) + =;
After the change, the answers are 9, 10, 10, and 11 in sequence.
2. In a 32-bit system, calculate the value of sizeof in the C ++ Program (5 points ).
Char STR [] = "http://www.ibegroup.com /"
Char * P = STR;
Int n = 10;
Calculate
Sizeof (STR) =? (1)
Sizeof (p) =? (2)
Sizeof (n) =? (3)
Void Foo (char STR [1, 100]) {
Calculate
Sizeof (STR) =? (4)
}
Void * P = malloc (100 );
Calculate
Sizeof (p) =? (5)
Answer: (1) 17 (2) 4 (3) 4 (4) 4 (5) 4
3. answer the following question (4 points)
(1) What is the use of ifndef/define/endif in the header file? Preprocessing
A: prevent header files from being repeatedly referenced.
(2). # What is the difference between I nclude and # I nclude "filename. h?
A: the former is used to include the library header files provided by the development environment, and the latter is used to include the header files compiled by yourself.
(3). Why should I add the extern "C" declaration to call the function compiled by the C compiler in the C ++ program?
A: The name of the function and variable in the symbol library after being compiled by C ++ is different from that in the C language. It is modified by extern "C ".
The number and function are compiled and connected in C language. C ++ programs cannot be directly called because the compiled name is different.
Use the C function. C ++ provides a C connection to exchange the specified symbol extern "C" to solve this problem.
(4) What data types are not allowed in switch?
Answer: Solid
4. answer the following question (6 points)
(1). 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 are the results of running the test function?
A: The output is "hello"
(2). Void test (void ){
Char * STR = (char *) malloc (100 );
Strcpy (STR, "hello ");
Free (STR );
If (STR! = NULL ){
Strcpy (STR, "World ");
Printf (STR );
}
}
What are the results of running the test function?
A: output "world"
(3). char * getmemory (void ){
Char P [] = "Hello World ";
Return P;
}
Void test (void ){
Char * STR = NULL;
STR = getmemory ();
Printf (STR );
}
What are the results of running the test function?
A: The pointer is invalid and the output is uncertain.
5. Compile the strcat function (6 points)
It is known that the prototype of the strcat function is char * strcat (char * strdest, const char * strsrc );
Here, strdest is the destination string and strsrc is the source string.
(1) do not call the string library functions of C ++/C. Compile the strcat function.
A:
VC source code:
Char * _ cdecl strcat (char * DST, const char * SRC)
{
Char * CP = DST;
While (* CP)
CP ++;/* Find end of DST */
While (* CP ++ = * SRC ++);/* Copy SRC to end of DST */
Return (DST);/* return DST */
}
(2) Why should strcat connect the content of strsrc to strdest?
A: It is convenient to assign values to other variables.
6. Is cstring a type security class in MFC?
A: No. You can use the cstring member function Format to convert other data types to cstring.
7. Why is a template class used in C ++.
A: (1) create a Data Structure with dynamic growth and reduction
(2) It is type-independent and therefore highly reusable.
(3) It checks the data type during compilation instead of runtime, ensuring the type security.
(4) It is platform-independent and portable.
(5) can be used for basic data types
8. What does csinglelock do.
A: Synchronize multiple threads to simultaneously access a data class.
9. What is newtextmetric.
Answer: The physical font structure is used to set the font height, width, and size.
10. When the program should use the thread, and when the single thread is highly efficient.
Answer: 1. Time-consuming operations use threads to improve application response
2. threads are used for parallel operations, such as the concurrent threads on the server side in the C/S architecture to respond to user requests.
3. In multiple CPU Systems, threads are used to improve CPU utilization
4. Improve the program structure. A long and complex process can be divided into multiple threads to become several independent or semi-independent processes.
Such a program is easy to understand and modify.
In other cases, a single thread is used. 1. Write and judge whether the four expressions of ABCD are correct. If so, write the value of A in the expression (3 points)
Int A = 4;
(A) A ++ = (a ++); (B) a ++ = (++ A); (c) (a ++) ++ = A; (d) (++ A) ++ = (a ++ );
A =?
A: C error. The left side is not a valid variable and cannot be assigned a value. You can change it to (++ A) + =;
After the change, the answers are 9, 10, 10, and 11 in sequence.
2. In a 32-bit system, calculate the value of sizeof in the C ++ Program (5 points ).
Char STR [] = "http://www.ibegroup.com /"
Char * P = STR;
Int n = 10;
Calculate
Sizeof (STR) =? (1)
Sizeof (p) =? (2)
Sizeof (n) =? (3)
Void Foo (char STR [1, 100]) {
Calculate
Sizeof (STR) =? (4)
}
Void * P = malloc (100 );
Calculate
Sizeof (p) =? (5)
Answer: (1) 17 (2) 4 (3) 4 (4) 4 (5) 4
3. answer the following question (4 points)
(1) What is the use of ifndef/define/endif in the header file? Preprocessing
A: prevent header files from being repeatedly referenced.
(2). # What is the difference between I nclude and # I nclude "filename. h?
A: the former is used to include the library header files provided by the development environment, and the latter is used to include the header files compiled by yourself.
(3). Why should I add the extern "C" declaration to call the function compiled by the C compiler in the C ++ program?
A: The name of the function and variable in the symbol library after being compiled by C ++ is different from that in the C language. It is modified by extern "C ".
The number and function are compiled and connected in C language. C ++ programs cannot be directly called because the compiled name is different.
Use the C function. C ++ provides a C connection to exchange the specified symbol extern "C" to solve this problem.
(4) What data types are not allowed in switch?
Answer: Solid
4. answer the following question (6 points)
(1). 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 are the results of running the test function?
A: The output is "hello"
(2). Void test (void ){
Char * STR = (char *) malloc (100 );
Strcpy (STR, "hello ");
Free (STR );
If (STR! = NULL ){
Strcpy (STR, "World ");
Printf (STR );
}
}
What are the results of running the test function?
A: output "world"
(3). char * getmemory (void ){
Char P [] = "Hello World ";
Return P;
}
Void test (void ){
Char * STR = NULL;
STR = getmemory ();
Printf (STR );
}
What are the results of running the test function?
A: The pointer is invalid and the output is uncertain.
5. Compile the strcat function (6 points)
It is known that the prototype of the strcat function is char * strcat (char * strdest, const char * strsrc );
Here, strdest is the destination string and strsrc is the source string.
(1) do not call the string library functions of C ++/C. Compile the strcat function.
A:
VC source code:
Char * _ cdecl strcat (char * DST, const char * SRC)
{
Char * CP = DST;
While (* CP)
CP ++;/* Find end of DST */
While (* CP ++ = * SRC ++);/* Copy SRC to end of DST */
Return (DST);/* return DST */
}
(2) Why should strcat connect the content of strsrc to strdest?
A: It is convenient to assign values to other variables.
6. Is cstring a type security class in MFC?
A: No. You can use the cstring member function Format to convert other data types to cstring.
7. Why is a template class used in C ++.
A: (1) create a Data Structure with dynamic growth and reduction
(2) It is type-independent and therefore highly reusable.
(3) It checks the data type during compilation instead of runtime, ensuring the type security.
(4) It is platform-independent and portable.
(5) can be used for basic data types
8. What does csinglelock do.
A: Synchronize multiple threads to simultaneously access a data class.
9. What is newtextmetric.
Answer: The physical font structure is used to set the font height, width, and size.
10. When the program should use the thread, and when the single thread is highly efficient.
Answer: 1. Time-consuming operations use threads to improve application response
2. threads are used for parallel operations, such as the concurrent threads on the server side in the C/S architecture to respond to user requests.
3. In multiple CPU Systems, threads are used to improve CPU utilization
4. Improve the program structure. A long and complex process can be divided into multiple threads to become several independent or semi-independent processes.
Such a program is easy to understand and modify.
In other cases, a single thread is used.