一家外企公司完整面试题和答案 Basic C/C++ (CC++ Programming interview questions and answers)1. The default member and base class access specifiers are different. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance. 2. Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own. Example code as following b inheritance a class a { }; class b:public a { }; 3. Yes, we can. For example: class complex { public: void operator + (complex &c) { } complex operator – (complex &c) { } } copy constructor: A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignment class Point2D { public Point2D() : x(0) , y(0) {} //default (no argument) constructor public Point2D( const Point2D & ) ; }; . 4. Public data members and member functions are accessible outside the class. Protected data members and member functions are only available to derived classes. Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes. 5. When only derived classes’
6. Primary value is implementation
In case of polymorphism (virtual functions) if a base class pointer(or reference) is allocated a pointer(or reference) of derived class the actual function called is determined only during runtime through the virtual table entry . This is runtime binding or late binding 7. Constructor can be virtual l, but destructor can not be virtual. Because each derived classes destructor behavior is not the same 8. A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. 9. A static data member or functions acts as a global object that belongs to its class type. Unlike other data members where each class object has its own copy, there is only one copy of a static data member per class type. A static data member is a single, shared object accessible to all objects of its class type. The const type members transforms an object into a constant. For example, const int bufSize = 512; // input buffer size defines bufSize to be a constant initialized with the value 512. Any attempt to change that value from within the program results in a compile-time error. For this reason, it is referred to as read-only. 10. Overloading is the practice of supplying more than one definition for a given function name in the same scope. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types. 11. If new fail, the return point will be NULL. For example as following int * ptr = new int(5); If(ptr==NULL) { } 12. Yes,for example as following Employee is derived from Person. A class may have an instance of another class. For example, an employee “has” a salary, therefore the Employee class has the HASA relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the Employee class. 13. For example: In c: char * p = (char*) malloc(100); free (p); p = NULL; in c++: char* p = new char[100]; delete[] p; p = NULL; 14. Is not the same. The result is 4. 15. A reference must always refer to some object and, therefore, must always be initialized; pointers do not have such restrictions. A pointer can be reassigned to point to different objects while a reference always refers to an object with which it was initialized. 16. A 17. When two base classes implement a method with the same name, or two base has the same
18. int data type. 19. Using try surrounded the code that maybe has exception, using catch hold of abnormal happen information. Example code as following 20. Using the way that pointer to a pointer together with reference as the parameter,the example code as following void test(int** & pp) { } int** ppt = NULL;
好好地考察一下你的Embedded English & C language理解力吧. 1.What is achieved by prefixing the 'static' keyword to a file-levelfunction or file-level variable declaration? 2.Describe the difference between the “IS A” and “HAS A” objectrelationships. Which is the stronger relationship and why? 3.Java & C# support interfaces directly with the “interface” keyword. 4.If a program requires a large number of execution contexts what can bedone to minimise thread scheduling overhead?
1. Explain what does #define do. 2. Please describe the ‘diamond problem’ with regards to multiple inheritance in object oriented programming. 3. Difference between Vector and List? 4. Given the root of a binary search tree, link all the nodes at the same level, by using an additional Node* level. 5. How do you find the max depth of a binary tree? 6. What is the difference between overriding and overloading? 7. If you had 5 red balls that contained 4 red balls and those red balls contained the original 5 red balls, then how many sets of sets of balls would I take to have a double set of red balls of varying sizes inside each next largest red ball? 8. Integer shift right-left, what happens by shifting to more than the integer bit size, etc.
|
|
来自: WUCANADA > 《interview》