) Xunlei C ++ Questions and answers

Source: Internet
Author: User

1. The output result of the following program is: (B)
# Include <iostream. h>
Void main ()
{
Char * A [] = {"hello", "the", "world"}; char ** Pa = A; PA ++; cout <"* Pa <Endl;} A) theworld B) the c) ello d) ellotheworld 2. it is known that the post-order traversal sequence of a binary tree is bfegcda, the middle-order traversal sequence is badefcg, and its pre-order traversal sequence is: (B)A) abcdefg B) abdcefg c) adbcfeg d) abecdfg 3. Common Features of stack and queue are: (C)A) both first-in-first-out (B) both first-in-first-out (c) only insert and delete elements in a short vertex (d) have nothing in common. 4. The following program runs as follows: ()# Include <iostream. h> void main () {int A, X; for (a = 0, x = 0; A <= 1 &&! X ++; A ++) {A ++ ;}cout <x <Endl ;}a) 21 B) 22 C) 32 d) 41 5. which of the following is incorrect? (B) While without a semicolonA) For (int A = 1; A <= 10; A ++); B) int A = 1; do {A ++;} while (A <= 10) c) int A = 1; while (A <= 10) {A ++;} D) for (int A = 1; A <= 10; A ++) A ++; 6. which of the following statements about array Initialization is true: (B)A) Char STR [2] = {"a", "B"}; B) Char STR [2] [3] = {"a", "B "}; c) Char STR [2] [3] = {'A', 'B'}, {'E', 'D'}, {'E ', 'F' }}; d) Char STR [] = {"A", "B "};

 

7. Which of the following statements are true: (B)A) At runtime, an inline function inserts the target code of the function into each place where the function is called. B) during compilation, inline functions Insert the target code of the function into each place where the function is called. c) inline functions of the class must be defined in the class. d) inline functions of the class must be defined in the class body by the keyword inline 8. which of the following statements about static members is true: (D)A) static data members can initialize in the class body B) static data members cannot be called by class objects c) static data members cannot be influenced by private controllers D) static data members can be called directly by class name 9. which of the following operators cannot be overloaded in the C ++ language: (C)A) * B)> = C): d) Description of polymorphism in Delete 10. The error is: (C)A) polymorphism in C ++ can be divided into polymorphism at compilation and polymorphism at runtime B) polymorphism at compilation can be implemented through function overload C) the Runtime polymorphism can be implemented through templates and virtual functions. // The template is a compilation polymorphism, while the virtual function is a runtimeD) The mechanism for implementing Runtime polymorphism is called dynamic binding 11. If the stack import sequence is E1, E2, E3, E4, E5, the possible output stack sequence is: (D)A) E3, E2, E5, E4, e1b) E2, E3, E5, E4, E1C) E3, E2, E4, E5, e1d) all of the above may be 12. The descriptions of classes and objects are incorrect: ()A) the class is the struct type in C language, and the object is the struct variable B in C language. The relationship between the class and the object is abstract and specific. c) the object is an instance of the class, an object must belong to a known Class D) class is a uniform description of several objects with common behavior 13. which of the following statements about arrays is false: (D)A) In C ++, the array name is Pointer B pointing to the first element of the array. The length of the array is N, and the value range is 0-n-1c) the size of the array must be determined during compilation. d) The array can only be passed to the function through the value parameter and reference parameter methods. Note: When the array is passed as a parameter to the function, there are two methods: by value and by reference.
In the value transfer method, to add the square brackets ([]) to the end of the array parameter, you only need to pass the array address (that is, the array name) to the function when calling the function.
For example, if array X is declared as int X [10];
The function is described as void byval_func (INT []);
The Int [] parameter tells the compiling program that the byval_func () function has only one parameter, that is, an array composed of int values. When calling a function, you only need to pass the array name to the function: byval_func (x); # include <stdio. h> void byval_func (INT []); void main (void) {int X [10]; int y; For (y = 0; Y <10; y ++) x [y] = y; byval_func (x);} void byal_func (int I []) {int y; For (y = 0; Y <10; y ++) printf ("% d/N", I [y]);} in the value transfer mode, array X is copied, the copied array is stored in the stack and then received and printed by the byval_func () function. The result is that the byval_func () function is a copy of the initial array. Therefore, modifying the passed array within the byval_func () function has no effect on the initial array.
The overhead of the value passing method is very large, because first it needs to completely copy the initial array and store the copy to the stack, which will take a considerable amount of running time, therefore, the value transfer method is less efficient. Second, copying the initialization array requires additional memory space (memory in the stack). Finally, the compiler needs to generate a part of the code used to copy the initial array, this will increase the program.
The address transfer method overcomes the disadvantages of the value transfer method. In the address transfer method, the pointer to the initial array is passed to the function, so the program becomes concise and saves the memory space in the stack. During address transfer, you only need to describe the function parameters as a pointer to the Data Type of the array element in the original form of the function.
For example, define an array X: int X [10];
The function is described as: int const_funt (const int *);
The const int * parameter tells the compiling program that the const_funt () function has only one parameter, that is, the pointer to an int type constant.
When calling a function, you only need to pass the array address to the function: const_func (x); # include <stdio. h> void const_func (const int *); void main (void) {int X [10]; int y; For (y = 0; Y <10; y ++) x [y] = y; constl_func (x);} void const_func (const int * I) {int y; For (y = 0; Y <10; y ++) printf ("% d/N", * (I + y);} in the value transfer mode, the initial array is not copied and stored in the stack. The const_func () function only receives a pointer to an int type constant. Therefore, when writing a program, ensure that the pointer is passed to const_func () A function is a pointer to an array composed of int constants. The const modifier prevents accidental modification of an element in the initial array. 14. Which of the following statements do you think is correct when referencing a standard library: (B)A) Statement # include "stdlib. h) Statement # include <stdlib. h> is correct, and the program execution speed ratio # include "stdlib. H "must be fast c) Statement # include <stdlib. h> and # include "stdlib. H "is correct and there is no difference in program execution speed D) Statement # include" stdlib. H "is an incorrect comment: Include" "is to start from the local directory and then find the system path, while include <> instead, first from the system directory and then from the local directory, 15. set a, B, c, d, M, and N to int variables, and a = 5, B = 6, c = 7, D = 8, m = 2, n = 2, then the logical expression (M = A> B) & (n = C> d) after calculation, the value of N is: (C)A) 0 B) 1 c) 2 D) 7 16. It cannot be used as the basis for calling the overload function: (C)A) Number of parameters B) parameter type C) function type D) function name 17. The output result of the following program is: (D)# Include <iostream. h>
Int func (int n)
{
If [n <1) return 1; else return N + func (n-1); Return 0;
}
Void main ()
{Cout <func (5) <Endl;} A) 0 B) 10 C) 15 d) 16 18. when a derived class object is created, the three constructor types are a (base class constructor), B (member object constructor), and C (derived class constructor) the Calling sequence of the three constructors is: ()A) abc B) acbc) cab d) CBA 19. If the parameter table does not contain any parameters when the user functions reload an operator, the operator is: (D )A) unary operator B) binary operator C) option A) and option B) Both may d) overload error Analysis: C ++ There must be at least one parameter in the heavy-duty operator of youyuan function. The heavy-duty operator must have one parameter, and the heavy-duty binary operator must have two parameters.. 20. The following sections are available: (D)?# Define f (x, y) (x) --; (y) ++ (x) * (y );... Int I, A = 3, B = 4; for (I = 0; I <5; I ++) f (a, B) printf ("% d, % d ", a, B); the output result is: () A) 3, 4 B) 3, 5C)-2, 5 d)-2, 9 21. the following for loop body execution times are: (A)For (int I (10), J (1); I = J = 0; I ++, j --) a) 0; B) 1; c) infinite; d) none of the above. 22. the output result of the following program is (D)Char * P1 = "123", * P2 = "ABC", STR [50] = "XYZ"; strcpy (STR + 2, strcat (P1, P2 )); cout <STR; A) xyz123abc B) z123abcc) xy123abc d) Error 23. the execution result of the following function is output. (B)Char STR [] = "Xunlei"; char * P = STR; int n = 10; printf ("% d, % d, % d/N", sizeof (STR ), sizeof (P), sizeof (n); A) 4, 4, 4 B) 7, 4, 4C) 6, 4, 4 d) 6, 6, 4 33. there are the following program segments: char * P, * q; P = (char *) malloc (sizeof (char) * 20); q = P; scanf ("% S % s ", p, q); printf ("% S % s/n", p, q); If you input ABC def from the keyboard, the output result is (A)A) def B) ABC defc) ABC d) D resolution: q = P; so p, q points to the same memory segment. scanf first writes ABC to the space pointed to by P, and then writes def to the space pointed to by Q, that is, the same space. Therefore, ABC is overwritten by def. 34. the following statements are available: struct _ thunder {int iversion; char CTAG; char cadv; int iuser; char Cend ;}thunder; int SZ = sizeof (Thunder, the value of the variable SZ will get (D)A) 11 B) 12 C) 13 d) 16 35. there are the following program segments: void getmemeory (char * P) {P = (char *) malloc (100);} void test () {char * STR = NULL; getmemory (STR ); strcpy (STR, "Thunder"); strcat (STR + 2, "downloader"); printf (STR) ;}the result of running the test function is: ( D )A) Thunder downloader B) under downloaderc) thunderownloader d) parse the program crash: Allocating space to pointers in a function is actually allocating space to the temporary variables of the pointer. After the function ends, this temporary variable also disappears. Str Still Null , No space is allocated for it. Strcpy () Yes.36. function call exec (V1, V2), (V3, V4, V5), V6, V7); In, the number of real parameters is (a) 4 B) 5 C) 6 d) 7 37. P is a pointer to m, a member of Class X, and s is an object of class X. Assign a value to M, (C)Is correct.A) s. P = 5 B) S-> P = 5c) s. * P = 5 d) * s. P = 5 38. the return value of function fun (char * P) {return P;} is (B)A) No exact value B) address value stored in row parameter P C) address of a temporary storage unit D) the address values 39.aand B of the row parameter P are all Integer Variables not equal to 0. The following relation is invariably set: (C)A) a * B/a * B = 1 B) A/B * B/a = 1C) A/B * B + A % B = A D) a/B * B =

40. The following description is provided: typedef struct st {long a; int B; char C [2];} new; which of the following statements is true: (C)A) The preceding description is invalid. B) ST is a struct type.
C) New is a struct type D) New is a struct variable 41. Which of the following expressions is correct: (C)A) 9 ++ B) (x + y) ++ C ++ d) ++ (a-B --) 42. in int B [] [3] = {1}, {3, 2}, {4, 5, 6}, {0};, sizeof (B) = (D ). A) 4 B) 12 C) 28 d) 48 43. The output result of the following program is: (D)# Define M (x, y, z) x * Y + zmain () {int A = 1, B = 2, c = 3; printf ("% d/N ", M (A + B, B + C, C + a);} A) 19 B) 17 C) 15 d) 12 44. if the following definitions and statements are available: int u = 010, V = 0x10, W = 10; printf ("% d, % d, % d/N", U, v, W); the output result is: ()A) 8, 16, 10 B) 10, 10, 10 C) 8, 8, 10 d) 8, 10, 10 45. The output result of the following program section is: (B)Int A = 5, B = 4, C = 3, D = 2; If (A> B> C) printf ("% d/N", d ); else if (C-1> = d) = 1) printf ("% d/N", D + 1); else printf ("% d/N ", d + 1); A) 2 B) 3 C) 4 d) Compilation error 46. there are the following program segments. The value of K is: (D)Enum {A, B = 5, c, d = 4, e} k; k = C; A) 3 B) 4 C) 5 d) 6 47. there are the following program segments: int I, n = 0; Double X = 1, Y1 = 2.1/1.9, y2 = 1.9/2.1; for (I = 1; I <22; I ++) x = x * Y1; while (X! = 1.0) {x = x * Y2; n ++;} printf ("% d/N", n); the execution result is: (A)A) 21 B) 22 C) infinite loop D) program crash 48. The tree structure is used to indicate the relationship between entities. (C)A) relational model B) mesh model C) Hierarchical Model D) the above three are 49. there are the following program segments: Char fun (char *); main () {char * s = "one", a [5] = {0}, (* F1) (char *) = fun, ch;} is correct in the call statement for function fun? (C)A) * F1 (& A); B) F1 (* s); c) F1 (& Ch) d) CH = * F1 (s); change to (* F1) (s) is correct 50. there are the following program segments: int c = 23; printf ("% d/N", C & C); the execution result is: (C)A) 0 B) 46 c) 23 d) None of the above

Related Article

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.