Tencent C ++ pen exam (I don't know the year)

Source: Internet
Author: User

 

If you do not know the correct answer, you can do it yourself. This article is intended for communication purposes. Please correct the mistakes. Thank you.

I. multiple choice questions (4 points per question, 15 questions, totally 60 points)
1. Consider the function prototype void Hello (int A, int B = 7, char * pszc = "*"). The following function call clock is invalid:
A Hello (5) B. Hello (5, 8) C. Hello (6, "#") D. Hello (0, 0 ,"#")

A: C. This is the declaration of the function. If a parameter has a default value, it must be placed at the end of the parameter list. When calling a function, values must be assigned to parameters without default values. The C value assignment type is incorrect.

2. Which of the following statements about overload functions are true:

A. the overload function must have different return value types. B. The number of overload function parameters must be different.
C. The overloaded function must have different parameter lists. d. The names of the overloaded functions can be different.

A: C. The function overload condition is that the number of function parameters is different and the parameter type is different. Different return values cannot constitute an overload.

3. Analyze the running results of the program:
# Include <iostream. h>
Class cbase
{
Public:
Cbase () {cout <"constructing cbase class" <Endl ;}
~ Cbase () {cout <"destructing cbase class" <Endl ;}
};
Class csub: Public cbase
{
Public:
Csub () {cout <"constructing csub class" <Endl ;}
~ Csub () {cout <"destructing csub class" <Endl ;}
};
Void main ()
{
Csub OBJ;
}
A. Constructing csub class B. Constructing cbase class
Constructing cbase class constructing csub class
Destructing csub class destructing cbase class
Destructing cbase class destructing csub class
C. Constructing cbase class
Constructing csub class
Destructing csub class
Destructing cbase class
D. Constructing csub class
Constructing cbase class
Destructing cbase class
Destructing csub class

A: C. This is about inheritance. When a subclass constructs an object, it first needs the parent class to call the constructor of the parent class, and then the subclass calls its own constructor to complete the object construction of the subclass. The subclass is removed during the analysis, and the parent class is removed.

This seems to be the same as stack. Advanced and later.

4. In a CPP file, a static global variable is defined. The following is a correct description:
A. This variable can only be used in the compilation module where the CPP is located.
B. The value of this variable cannot be changed.
C. This variable cannot be referenced in the member functions of the class.
D. This variable can only be of the basic type (such as int and char) and cannot be of the C ++ type.

A:. Static modified variable memory is on the stack. The static variable here is still a global variable. Of course, this variable is used in the compilation module where the CPP is located. The difference between static local variables and global variables lies in the difference in scope. Static variables can only be accessed locally. However, static variables are not destroyed because the function execution is complete.

5. Observe the following code:
Class classa
{
Public:
Virtual ~ Classa (){};
Virtual void functiona (){};
};
Class classb
{
Public:
Virtual void functionb (){};
};
Class classc: Public classa, public classb
{
Public:
};

Classc aobject;
Classa * pA = & aobject;
Classb * pb = & aobject;
Classc * Pc = & aobject;
Which of the following statements about the values of PA, Pb, and PC is true:

A. Pa, Pb, and PC have the same value. B. PC = pa + Pb
C. Pa and Pb are different. D. PC is not equal to or equal to Pb.

A:. They are the addresses of aobject objects. So it is the same. However, although the PA, Pb, and PC values are the same, they are different when accessing data. Pa can only access functions in a, and Pb can only access functions in B. The PC can access functions in a B c. In pointer assignment, the pointer type is implicitly converted.

6. Refer to code 1.5. Assume that classa * pa2 is defined. The correct code below is:
A. pa2 = static_cast <classa *> (PB );
B. Void * pvoid = static_cast <void *> (PB );
Pa2 = static_cast <classa *> (pvoid );
C. pa2 = Pb;
D. pa2 = static_cast <classa *> (static_cast <classc *> (PB ));

Answer: d

7. Refer to the Code 1.5. The following statement is insecure:
A. Delete pa B. Delete Pb C. Delete PC

A: B. B is incorrect because B does not write the destructor. The default destructor is not a virtual one. In this way, when Pb is to be destroyed, only the memory directed to the PC is destroyed, and the memory directed to PB is not released, which causes memory leakage.

8. The running results of the following programs are:
# Include <iostream. h>
Void main ()
{
Int A = 2;
Int B = ++;
Cout <A/6 <Endl;
}
A.0.5 B .0 c0.7 d.0.6666666-

A: B. A ++ is equal to 3. But a is of the int type. So 3/6 was rounded down. 0 is output.
9. The following code is provided:
# Define add (x, y) x + y
Int M = 3;
M + = m * Add (M, M );
Then the m value is:

A.15 B .12 c.18 d.58

A:. This is a macro. Be sure to replace it! So M = m + (M * m + M) = 15;

10. The following is a weighted graph. The length of the Key Path from node A to node D is:
A.13 B .15 C.28 d.58

A: No figure is displayed on the Internet. No answer. It's a problem in the data structure.

11. Which of the following template statements is true:
A. template <typename T1, T2>
B. template <class T1, T2>
C. template <class T1, class T2>
D. template <typename T1; typename T2>

A: C. All the template-defined data type variables require typename and cannot be omitted. A B is omitted. D is not separated by semicolons.
12. Which of the following statements in Windows programming are true:

A. Two windows. Their window handles can be the same B. Two windows, and their processing functions can be the same
C. Two windows. Their window handles and window processing functions cannot be the same.

A: B. B is obviously correct. As long as it is a window, they can call the member functions in cwnd, such as setwindowtext. The handle cannot be the same. The handle is a unique pointer to a resource.

13. Which of the following situations cannot be implicitly converted to a by B?
A. Class B: Public A {} B. Class A: Public B {}
C. Class B {operator A ();} D. Class A {A (const B &);}

A: B. This should also be an issue of inheritance. I have talked about virtual functions. B is the parent class of. The parent class cannot be implicitly converted to a subclass. On the contrary.

14. A company uses a package to filter data from and out of the company's lan. If proxy servers are not considered, the following error message is displayed: "This firewall can ()".
A. enable employees to access only the IP addresses of the companies connected to their services on the Internet.
B. Only HTTP protocol is allowed. Other protocols, such as TCP/UDP, are not allowed.
C. prevent employees from directly accessing the FTP address with the FTP server port number 21.
D. Only allow computers with certain IP addresses in the company to access external networks

Answer: B

15. The ASCII value of digit 0 is 48. If there are the following programs:
Main ()
{
Char A = '1', B = '2 ';
Printf ("% C,", B ++ );
Printf ("% d \ n", B-);
}
The output result after the program runs is:
A.3, 2 B .50, 2 C.2, 2 D.2, 50

A: C. 0 is 48, 1 is 49,2 is 50, 3 is 51

B ++ should note that it is right ++, not left ++. Note that their differences will not be wrong. B ++ returns B. The character is 2. This is B 51,51-49 = 2. The output integer is 2.

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.