Morgan Stanley OA题库

原创 2015年11月18日 20:27:07


【Q1】 Which of the following statements accurately describe unary operator overloading inC++?

A.    Aunary operator can be overloaded with one parameter when the operator functionis a class member.

B.    A unary operator can beoverloaded with one parameter when the operator function is free standingfunction (not a     class member).

C.    Aunary operator can only be overloaded if the operator function is a classmember.

D.    A unary operator can beoverloaded with no parameters when the operator function is a class member.

E.    A unary operator can beoverloaded with no parameters when the operator function is a free standingfunction (not a class member).


【Q2】 Which of the following statements correctly describe the code below in C++?

#definelanguage 437                   //Line1

#iflanguage < 400

#undeflanguage                          //Line2

#else                                          //Line3

#definelanguage850                   //Line4

#ifdeflanguage                           //Line5

printf("%d",language);        //Line 6



A.    Anerror or warning will occur on Line 6 because a macro cannot be used as part ofa preprocessor directive.

B.    Anerror or warning will occur on Line 2 because #undef is not a valid preprocessordirective.

C.    An error or warning willoccur on Line 4 because language has already been defined.

D.    IfLine 1 is changed to #define language 300, Line 6 will print "850".

E.    Anerror or warning will occur on Line 3 because #else can only be used as thelast conditional in the chain.


【Q3】 Whichof the following statements regarding the benefits of using template functionsover preprocessor #define macros are correct?

A.    Apreprocessor macro expansion cannot work when user-defined types are passed toit as arguments.

B.    Sincethe preprocessor does the macro expansion and not the compiler, the buildprocess takes a longer period of time.

C.    While expanding #definemacros, the preprocessor does no type checking on the arguments to the macro.

D.    Apreprocessor macro expansion incurs a performance overhead at runtime.

E.    It is simple to step into a template functioncode during the debugging process.


【Q4】 Whichof the following are container adapters in the STL (Standard Template Library)in C++?

A.    list

B.    map

C.    stack

D.    queue

E.    deque


【Q5】 Whichof the following correctly identify benefits of the getline() member functionfor cin over the extraction operator in C++?

A.    The getline()function by default, accepts whitespace, and returns on seeing the /ncharacter, whereas the extraction operator returns when it encounters anywhitespace character.

B.    Delimiters indicating end of input can be specified to the getline()function, whereas the extraction operator has no such facility.

C.    The getline() function can beoverloaded to accept different argument types, whereas the extraction operatorcannot be overloaded.

D.    The number of bytesto read can be specified to the getline() function, whereas it cannot be donewith the extraction operator.

E.    The getline() function can beused like a manipulator with cin, whereas the extraction operator cannot beused as a manipulator.


【Q6】 Inwhich of the following scenarios is a Copy Constructor called or invoked?

A.    Whenno conversion function exists for converting the class object to another classobject

B.    Whenan existing object is assigned an object of its own class

C.    When a function receives asan argument, an object of the class, by value

D.    When a function returns anobject of the class by value

E.    When creating an object andinitializing it with an object of its own class


【Q7】 Whichof the following statements describe the result when standard new cannotallocate the requested storage in C++?  (Note: older compilers maynot implement standard behavior).

A.    It throws a bad_allocexception.

B.    Itreturns null.

C.    Itreturns silently with no effect on the expression.

D.    Itthrows an insufficient_memory exception.

E.    Itlogs an error message to the mem_err.log file.


【Q8】 InC++, which of the following is the best declaration for an overloadedoperator[] to allow read-only access (and only read-only access) to the data?




//declaration goes here



A.    T&operator[](size_t i);

B.    constT& operator[](size_t i);

C.    const T&operator[](size_t i) const;

D.    T&operator[](size_t i)const;

E.    T&operator[](const size_t i);


【Q9】 Whichof the following declarations of function main are standard or standardconforming extensions? (Please note that some compilers accept ill-formed maindeclarations, these should be considered incorrect).

A.    int main()

B.    voidmain(char* argv[], int argc)

C.    int main(int argc, char*argv[])

D.    voidmain()

E.    intmain(int argc, char* argv[], char* arge[])


【Q10】 Whatis the correct declaration for a file stream insertion operator for a classmy_stuff::my_class as indicated in the C++ code snippet below?





class my_class



int i;



//Declaration goes here




A.    std::ofstream&operator<<(std::ofstream& ofs, const my_class&);

B.    constmy_class& operator<<(const my_class&)

C.    std::fstream&operator<<(std::fstream& fs, const my_class&)

D.    std::ifstream&operator<<(std::ifstream& ifs, const my_class&)

E.    voidoperator<<(const my_class&)


【Q1】 Which of thefollowing statements accurately describe the new[] operator in C++?

A.    It calls the class defaultconstructor for each element of the array.

B.    Itcalls the class copy constructor for each element of the array.

C.    It calls operatornew[](size_t).

D.    Itcalls operator new[](size_t, int).

E.    It stores the number of objects allocated.


【Q2】 What is theorder of destructor calls for an object of class Y inherited from class X thathas an object of class A as data member of class Y in C++?

A.    ~Y()



B.    ~X()



C.    ~Y()



D.    ~A()



E.    ~X()




【Q3】 In C++, thereis a standard global object wcin of type wistream. What is the template type ofthe wistream typedef?

A.    std::basic_istream<wchar_t,char_traits<wchar_t> >

B.    std::basic_istream<char,char_traits<char> >

C.    std::istream<char,char_traits<char> >

D.    std::istream<wchar_t,char_traits<wchar_t> >

E.    std::wistream<char,char_traits<char> >


【Q4】 How can a C++developer use the placement new syntax to make new allocate an object of classSomeClass at a particular memory address stored in a pointer type variablenamed pmem?

A.    newSomeClass(pmem);

B.    new(pmem) SomeClass;

C.    newpmem SomeClass;

D.    newSomeClass pmem;

E.    new(pmem, SomeClass);


【Q5】 Under which ofthe following conditions will a C++ developer use polymorphism?

A.    Whenthere is a looping construct that uses a continue more than once

B.    When there is a needfor the code written today to call code written tomorrow

C.    When there is a needto check for the type of an object to determine which function must be called

D.    Whenthere is a need to check the value of a variable to determine which of two ormore functions to call

E.    Whenthere is a need to modify the existing interface of a class


【Q6】 Protected, orprivate, inheritance, as opposed to public inheritance, models which type ofrelationship in C++?

A.    Has-a

B.    Is-implemented-in-terms-of

C.    Was-a

D.    Can-only-have-one-of

E.    Shares-a-relationship-with


【Q7】 Which of thefollowing statements regarding functions' default arguments in C++ are correct?

A.    Defaultarguments cannot be of pointer type.

B.    Defaultarguments cannot be of a user-defined type.

C.    Default arguments cannever precede non-default arguments.

D.    Defaultarguments exist in the global heap and not on the function's stack.

E.    Defaultarguments are not considered for generating the function's signature.


【Q8】 In thedeclaration below, p is a pointer to an array of 5 int pointers:


Which ofthe following statements can be used to allocate memory for the first dimensionin order to make p an array of 3 arrays of 5 pointers to type int?

A.    p= new int [3][5]*;

B.    p= new int (*)[3][5];

C.    p= new int [3]*[5];

D.    p = new int *[3][5];

E.    p= new int (*[3])[5];


【Q9】 Which of thefollowing operators must be overloaded by function objects in the StandardTemplate Library?

A.    operator+()

B.    operator++()

C.    operator==()

D.    operator ()()

E.    operator[]()


【Q10】 A C++ developerwants to explicitly specialize the template function below for the char * type:

template<class T> void fn(T a){...}

Which ofthe following methods can the developer use to carry out this specialization?

A.    voidfn<char*>(char* a){...}

B.    template <>void fn<char*>(char* a){...}

C.    voidfn<char*>(T a){...}

D.    template<class T> void fn(char* a){...}

E.    template<class T> void fn<char*>(T a){...}


【Q1】 Which of thefollowing statements describe the results of executing the code snippet belowin C++?

int var= 1;



int i = i;



A.    The i within mainwill have an undefined value.

B.    Thecompiler will allow this statement, but the linker will not be able to resolvethe declaration of i.

C.    Thei within main will have a value of 1.

D.    Thecompiler will not allow this statement.

E.    The result iscompiler-dependent.


【Q2】 Which of thefollowing methods can a developer use to override the default terminate()function in C++?

A.    Writethe terminate() function with two int arguments.

B.    Writethe terminate() function with a runtime_error argument.

C.    Pass the address ofthe overriding function to the set_terminate() function.

D.    Writethe terminate() function with one int argument.

E.    Writethe terminate() function with a runtime_exception argument.


【Q3】 Which of thefollowing are not pre-processor directives in C++?

A.    #ifndef

B.    #ifdef

C.    #elif

D.    #define

E.    #extern


【Q4】 Which allocatormember function do standard containers use to acquire storage for their elementsin C++?

A.    std::allocator<>::allocate(size_t)

B.    std::allocator<>::malloc(int)

C.    std::allocator<>::make(size_t)

D.    std::allocator<>::new(size_t)

E.    std::allocator<>::acquire(size_t)


【Q5】 Which of thefollowing statements provide a valid reason not to use RTTI for distributed(i.e. networked between different platforms) applications in C++?

A.    RTTI does not have standardized run-timebehavior.

B.    RTTIuses too much memory.

C.    RTTIis too slow.

D.    RTTI'sperformance is unpredictable/non-deterministic.

E.    RTTI frequentlyfails to function correctly at run-time.


【Q6】 Which of thefollowing functions of the ifstream class can be used to determine the currentposition of the stream's get pointer in C++?

A.    voidtellg(pos_type&)

B.    pos_type tellg()

C.    pos_typetellp()

D.    voidtellp(pos_type&)

E.    voidseekg(pos_type&)


【Q7】 Which of thefollowing C++ keywords are designed to speed up execution of a C++ function?

A.    friend

B.    static

C.    extern

D.    inline

E.    member


【Q8】 Which of thefollowing template declarations provide the correct syntax to write a templateclass

template<class T> class Derived;

that hasto inherit from another template class

template<class T> class Base;


A.    template<class T, class Q> class Derived<Q> : public Base<T>

where Q can be used as the templatized type for class Derived.

B.    template<class T, class Q> class Derived : public Base

where Q can be used as the templatized type for class Derived.

C.    template <class T, class Q> class Derived :public Base<T>

where Q can be used as the templatized type for class Derived.

D.    template<class T, class Q> class Derived<Q> : public Base

where Q can be used as the templatized type for class Derived.

E.    template<class Q> class Derived<Q> : public Base


【Q9】 Which of thefollowing options describe the expected overhead for a class that has 5 virtualfunctions?

A.    Every object of theclass holds the address of a structure holding the addresses of the 5 virtual functions.

B.    Everyobject of the class holds the addresses of the 5 virtual functions.

C.    Every object of the class holdsthe address of the first virtual function, and each function in turn holds theaddress of the next virtual function.

D.    Everyobject of the class holds the address of a link list object that holds theaddresses of the virtual functions.

E.    Every object of the class holdsthe address of the class declaration in memory, through which the virtualfunction calls are resolved.


【Q10】 Which of thefollowing reasons describe why a destructor cannot throw an exception in C++?

A.    Itcan invoke the terminate() handler.

B.    Sincethe object is being destroyed, it is illogical to throw an exception then.

C.    TheC++ language does not permit it; a throw statement in a destructor will becaught as an error by the compiler.

D.    A destructor may beinvoked as a result of stack unwinding while an exception is being handled.

E.    Adestructor in C++ cannot implement a try...catch block.

【Q1】 Which of thefollowing define valid string constants in C++?

A.    #defineMESSAGE "Whoever said that you could run this program" &

"must not have known what you'd do."

B.    #defineREETING = "Hello!"

C.    #defineMESSAGE = "This is a long message, but I know you have"

#define MESSAGE = MESSAGE + " plenty of time to read it."

D.    #define ERROR_MSG"You did something very very wrong and now the /

program will terminate."

E.    #defineMESSAGE "Hello "

#concat MESSAGE & #UserName


【Q2】  What memberfunction of std::fstream could a C++ developer invoke in order to change thetarget output filebuf of the fstream?

A.    setbuffer

B.    setfilebuf

C.    rdbuf

D.    filebuf

E.    streambuf


【Q3】 Which of thefollowing options are returned by the typeid operator in C++?

A.    Areference to a const std::type_info object

B.    Aconst std::type_info object

C.    Aconst reference to a const std::type_info object

D.    Areference to a std::type_info object

E.    A const reference to a std::type_info object


【Q4】 Which of thefollowing statements describe correct methods of handling C++ exceptions?

A.    Once an exception is thrown,the compiler unwinds the heap, freeing any memory dynamically allocated withinthe block from which the exception was thrown.

B.    In a hierarchy of exception classes, the order of handling exceptionscan be from the most specific class to the most general class.

C.    If an exception is caught byits address or pointer, it is the responsibility of the thrower to release thememory occupied by the exception.

D.    Catching an exceptionby reference is preferable to catching it by value.

E.    Towrite an exception handler, it is essential to know the concrete class ofexception to catch.


【Q5】 Which of thefollowing statements correctly describe functions of the endl manipulator forthe ostream object cout in C++?

A.    Itonly flushes the standard output stream.

B.    It puts a newlinecharacter into the standard output stream and flushes the standard outputstream.

C.    Itputs an end-of-output character into the standard output stream.

D.    Itonly puts a newline character into the standard output stream.

E.    Itindicates end-of-output and closes the standard output stream.


【Q6】 In C++, whichof the following statements accurately describe a base class destructor callinga virtual function override of a derived class?

A.    Thebase class destructor calls the virtual function override of the derived classthrough the vtable.

B.    The base class destructor cannot call the virtual function override ofthe derived class because the derived class portion of the data may be in anundefined state.

C.    The base classdestructor calls the virtual function of the base class and not of the derivedclass.

D.    The C++ compiler maintains theoverridden virtual function pointers in a separate structure when it sees thecall in a destructor. The call is then resolved through this structure.

E.    The language does not permitcalling a virtual function override in either a constructor or the destructorof the base class.


【Q7】 In which of thefollowing situations is the unexpected() handler called in C++?

A. Whena function throws an exception of an undefined type

B. Whenan appropriate catch block is not present in the calling function to catch anexception thrown by the called function

C. Whenthe stack gets corrupted during unwinding as a result of a thrown exception

DWhen a function that has an "exceptionspecification" throws an exception not listed in that specification.

E. Whena constructor throws an exception


【Q8】 Which of thefollowing classes must be instantiated so that the object can be used both forreading and writing to the same file in C++?






【Q9】 A class derinherits from class base and the functions are defined in the code below:

voidSomeFunc(base& b){ ... }

voidSomeFunc(base b){ ... }

voidSomeFunc(der& b){ ... }

voidSomeFunc(der b){ ... }




der d;



In thecall to SomeFunc(d), which of the following overloads of the SomeFunc functionwill be executed in C++?

A. voidSomeFunc(base& b){ ... }

BThe compiler will generate an ambiguous callerror.

C. voidSomeFunc(der& b){ ... }

D. voidSomeFunc(base b){ ... }

E. void SomeFunc(derb){ ... }


【Q10】 The code belowgenerates the compiler error "'Derived::data' is ambiguous". In C++,which of the following steps can be taken to rectify it so that obj has onlyone instance of data?




int data;


class DerivedOne: public Base {};

classDerivedTwo : public Base {};

classDerived : public DerivedOne, public DerivedTwo {};




Derived obj; = 5;


A.Inherit class Derived from DerivedOne and DerivedTwo as virtual publicDerivedOne and virtual public DerivedTwo.

BInherit classes DerivedOne and DerivedTwo fromBase as virtual public Base.

C. Inherit classes DerivedOne and DerivedTwofrom Base as public virtual Base.

D.Inherit class Derived from DerivedOne and DerivedTwo as public virtualDerivedOne and public virtual DerivedTwo.

E.Inherit either class DerivedOne or class DerivedTwo from Base as virtual publicBase

【Q1】 Which of thefollowing statements correctly describe C preprocessor directives in C++?

A.    The#pragma directive is machine-independent.

B.    Preprocessordirectives are processed before macros are expanded.

C.    The#import directive is used to copy code from a library into the program's sourcecode.

D.    Anynumber of #else directives can be used between an #if and an #endif.

E.    The#include directive is used to identify binary files that will be linked to theprogram.


【Q2】 In a hierarchyof exception classes in C++, which of the following represent possible ordersof catch blocks when a C++ developer wishes to catch exceptions of more thanone class from a hierarchy of exception classes?

A.    Classesbelonging to the same hierarchy cannot be part of a common set of catch blocks.

B.    The most derivedclasses must appear first in the catch order, and the parent classes mustfollow the child classes.

C.    Themost derived classes must appear last in the catch order, and the parentclasses must precede the child classes.

D.    Theorder is unimportant as exception handling is built into the language.

E.    Multipleclasses can be caught in a single catch clause as multiple arguments.


【Q3】 Which of thefollowing options describe the functions of an overridden terminate() function?

A.    Itperforms the desired cleanup and shutdown processing, and then throws atermination_exception.

B.    It performs the desiredcleanup and shutdown processing, and then returns an error status value to thecalling function.

C.    It performs thedesired cleanup and shutdown processing, and then calls abort() or exit().

D.    It performs the desired cleanupand shutdown processing, and if it has restored the system to a stable state,it returns a value of "-1" to indicate successful recovery.

E.    Itperforms the desired cleanup and shutdown processing, and then calls the unexpected()handler.


【Q4】 What is thecorrect syntax for portable fstream file paths?

(e.g.the string you would pass to std::fstream:open() to open a file.)

A.    "::directory:file.bin"

B.    "C:/Directory/File.bin"

C.    "/directory/file.bin"

D.    "C://Directory//File.bin"

E.    std:fstream filepaths are not portable.


【Q5】 When a CopyConstructor is not written for a class, the C++ compiler generates one. Whichof the following statements correctly describe the actions of thiscompiler-generated Copy Constructor when invoked?

A.    The compiler-generated Copy Constructor makes the object beingconstructed, a reference to the object passed to it as an argument.

B.    Thecompiler-generated Copy Constructor does not do anything by default.

C.    The compiler-generated CopyConstructor performs a member-wise copy of the object passed to it as anargument, into the object being constructed.

D.    Thecompiler-generated Copy Constructor tags the object as having beenCopy-Constructed by the compiler.

E.    Thecompiler-generated Copy Constructor invokes the assignment operator of theclass.


【Q6】 Which of thefollowing are accurate statements regarding the declaration and definition ofan object in a working C++ program?

A.    Anobject can be declared only once.

B.    Anobject can be defined multiple times.

C.    If an object is declaredand used, it must be defined.

D.    An object can be declaredmultiple times but can be defined only once.

E.    Anobject must be defined for each time it is declared.


【Q7】 In C++, thestandard fstream class has a member function exceptions that set the exceptionmask for the stream. Which of the following are valid choices for the mask?

A.    ios::openbit

B.    ios::eofbit

C.    ios::badbit

D.    ios::failbit

E.    ios::retybit


【Q8】 Of the optionsbelow, which allocate a buffer of 100 bytes from the heap in C++?

A.    char*buffer = new[100];

B.    unsigned char* buffer= (unsigned char*)malloc(100);

C.    char* buffer =(char*)malloc(100);

D.    unsignedchar* buffer = new[100];

E.    byte*buffer = heap(100);


【Q9】 Which of thefollowing statements correctly identify features of overloading the C++increment operator?

A.    If the increment operators arenot overloaded, then the results of any expression using them are undefined, asthe compiler uses the default increment operators to evaluate the expression.

B.    The prefix from isdeclared as

return_type operator++()

and the postfix form as

return_type operator++(int)

C.    Ifthe postfix form is not defined, the prefix form is used by the compiler.

D.    Theprefix from is declared as

return_type operator++(int)

and the postfix form as

return_type operator++()

E.    If the incrementoperators are not overloaded, the compiler generates defaults which do nothing.The state of the object remains unchanged.


【Q10】 Which of thefollowing is a valid function prototype for a C++ function named Display, whichreceived as STL vector object as an argument?

A.    template<class T> void Display(std::vector& obj);

B.    template<class T> void Display<T>(std::vector& obj);

C.    template <classT> void Display(std::vector<T>& obj);

D.    template<class T> void Display<T>(std::vector<T>& obj);

E.    template<class T, class Q> void Display<T>(std::vector<Q>& obj);

【Q1】 When using C++iostreams as shown in the code snippet below, which of the following statementswill print ”3.14” to the display?




intmain(int argc, char* argv[])


using namespace std;

const double pi = 3.14159265358979323;


//Statement (s) goes here



A.    cout<< format(“%.2f”, pi) << endl;

B.    cout<< setw(3) << pi << endl;

C.    cout <<setprecision(3) << pi << endl;

D.    cout.precision(3);

cout << pi << endl;

E.    cout<< “%.2f” << pi << endl;


【Q2】 Which of thefollowing C++ keywords are used to create an alias of a type?

A.    const

B.    typedef

C.    ref

D.    enum

E.    #define


【Q3】 Which of thefollowing are appropriate uses of the const type-modifier when declaring ordefining variables in C++?

A.    When instancingobjects that should never be modified.

e.g. const Point2D origin = Point2D(0.0., 0.0);

B.    When definingmathematical constants wht never change.

e.g. const double sqrt2 = std::sqrt(2.0);

C.    When defining areference parameter that is not modified by the called function.

e.g. complex add(const complex& a, const complex& b);

D.    Whendefining flags that should rarely be changed.

e.g. const bool exit_application = false;

E.    Whendefining a reference to ensure it will always reference the same object.

e.g. const Object& assign_once = other_object;



【Q4】 Which of thefollowing statements accurately present the access control in C++?

A.    Protectedmembers of a class are accessible only by member functions and friends of thatclass.

B.    Private members of aclass are accessible only by member functions and friends of that class.

C.    Protectedmembers of a class are accessible only by member functions of that class.

D.    Privatemembers of a class are accessible only by member functions of that class.

E.    Publicmembers of a class are accessible only by everyone except friend functions.


【Q5】 Forstd::vector, which C++ member function should be invoked to pre-allocatestorage without constructing new elements?

A.    std::vector::malloc(int)

B.    std::vector::reserve(size_t)

C.    std::vector::new(size_t)

E.    std::vector::allocate(size_t)

E.    std::vector::resize(size_t)


【Q6】 Given the C++code below, which of the following are correct declarations for a copyconstructor for a class named Vector?






//declaration goes here


A.    Vector(constVector&) const;

B.    Vector(const Vector&copy_me);

C.    Vector(constVector& v);

D.    Vector(constVector&);

E.    Vector(constVector* copy_me) const;


【Q7】 In C++, whichof the following declarations will correctly declare an overloaded insertionoperator for the count object that displays an object of a user-defined classMyString?

int main



cout << objMyString << endl;


A.    voidMyString::operator <<(ostream&);

B.    voidMyString::operator <<( MyString&);

C.    ostreamoperator <<( MyString&);

D.    std::ostream operator<<(std::ostream&, MyString&);

E.    voidstd::ostream operator <<(MyString &);


【Q8】 Which of thefollowing operations of the list<T> container take a variable amount oftime to complete in C++?

A.    Access item in the middle of the list

B.    Insert item in the middle of the list

C.    Insertitem at the beginning of the list

D.    Insertitem at the end of the list

E.    Accessitem at the end of the list


【Q9】 Which of thefollowing statements accurately describe the condition that can be used forconditional compilation in C++?

A.    The condition can depend on the value of programvariables.

B.    The condition can depend on the values of anyconst variables.

C.    The condition can use thesizeof operator to make decisions about compiler-dependent operations, based onthe size of standard data types."

D.    The condition can depend on thevalue of environmental variables.

E.    Thecondition must evaluate to either a "0" or a "1" duringpre-processing.


【Q10】 Which of thefollowing statements correctly describe the C++ language and its libraries?

A.    Itis possible to declare a function pointer to the constructor of a C++ class.

B.    Though one can override the<< operator of the ostream class, it is not possible to do so for theofstream class because it does not use a buffered output stream.

C.    The C++ language doesnot have built in features for persisting or serializing objects to disk andback.

D.    Itis not possible to declare a pointer to a private data member of a C++ class.

E.    Ifthe << operator of the ostream class has been templatized, it cannot bespecialized.

【Q1】 Whichof the following must be ensured in order to implement a polymorphic functionin C++?

A.    There has to be a pointer ofthe derived class that has implemented the polymorphic function that holds theaddress of the derived class object.

B.    Thefunction must be declared as virtual in both the base class and in the derivedclass that overrides the function.

C.    Thefunction must be declared as pure virtual.

D.    There has to be a base classpointer holding the address of a base or derived class object that hasimplemented the polymorphic function.

E.    The function must be declared as virtual in thebase class.


【Q2】 InC++, which of the following are valid uses of the std::auto_ptr templateconsidering the class definition below?




virtual ~Object() {}



A.    std::auto_ptr<Object> pObj(new Object);

B.    std::vector<std::auto_ptr <Object*> > object_vector;

C.    std::auto_ptr<Object*> pObj(new Object);

D.    std::vector<std::auto_ptr <Object> > object_vector;

E.    std::auto_ptr<Object> source()


return new Object;



【Q3】 Whichof the following statements accurately describe the C++ code excerpt below?

int* arr= new int[10];


A.    deletewill fail.

B.    Anexception may be thrown at time.

C.    delte[] arr; must be used to properly deallocatearr.

D.    Thecompiler will emit a diagnostic error.

E.    The free-store may be corrupted.


【Q4】 Referringto the sample code below, why are the default and copy constructors declared asprotected?

class A



void f();




cout << "A:A()" << endl;


A(const A&){}


A.    To ensure that instances of A cannot be copied

B.    Toensure that instances of A cannot be created via new by a more derived class

C.    Toensure that instances of A can only be created by subclasses of A

D.    Toensure that A cannot be instantiated on the stack

E.    Toensure that A cannot be used as a base class


【Q5】 Inwhich of the following scenarios should a destructor be declared virtual in abase class?

A.    Whenthe destructor of the base class will be doing the clean-up of the derivedclass data;

B.    When the developer wants to ensure that a derived class destructor isinvoked when an instance is destroyed through a base class pointer;

C.    Whenan implementation for the derived class destructor is not desired.

D.    Whena derived class allocates system resources which are released in itsdestructor;

E.    Whenthe default constructor of the base class is declared as virtual;


【Q6】 AC++ developer wants to handle a static_cast<char*>() operation for theclass String shown below. Which of the following options are valid declarationsthat will accomplish this task?





//declaration goes here



A.    char*operator();

B.    char*operator char*();

C.    Stringoperator char*();

D.    operator char*();

E.    char*operator String();


【Q7】 Whichof the following expression(s) will not cause an error when used to replace the***** in the C++ code excerpt below?






static int m_Out;

class Inner



static int m_In;

void Display();




intOuter::m_Out = 10;

intOuter::Inner::m_In = 25;


voidOuter::Inner::Display() {  std::cout << m_Out << std::endl;  }




Outer    objOut;

Outer::Inner objIn;









【Q8】 Whichof the following statements correctly describe the results of executing thecode below in C++?


usingnamespace std;





static int stat;


static int GetStat(){ return stat; }



intExBase::stat = 25;


classExDer1 : public ExBase



friend int Der1Fn(){ return ExBase::stat; }



classExDer2 : public ExBase{};


classExDer : public ExDer1, public ExDer2{};


A.    intmain()


ExDer d;

cout <<d.Der1Fn() << endl;


will result in an ambiguity error from the compiler.

B.    intmain()


ExDer d;

cout <<d.GetStat() << endl;


will display an output as "25".

C.    intmain()


cout << ExDer1::GetStat() << endl;


will result in an ambiguity error from the compiler.

D.    class ExDer1 : public ExBase



friend int Der1Fn(){ return ExBase::stat; }


will result in an access error from the compiler.

E.    intmain()


cout << ExDer1::ExBase::GetStat() << endl;


will display an output as "25".


【Q9】 Giventhe following program snippet, what can we conclude about the use ofdynamic_cast in C++?




//Someoneelse's code,E.g. library




virtual ~IGlyph(){}

virtual std::string Text()=0;

virtual IIcon*      Icon()=0;







virtual ~IWidgetSelector(){}


virtual void    AddItem(IGlyph*)=0;

virtual IGlyph* Selection()=0;




classMyItem : public IGlyph



virtual std::string Text()


return this->text;



virtual IIcon* Icon()


return this->icon.get();



void Activate()


std::cout << "My Item Activated" <<std::endl;



std::string          text;

std::auto_ptr<IIcon> icon;



voidSpiffyForm::OnDoubleClick(IWidgetSelector* ws)


IGlyph* gylph = ws->Selection();

MyItem* item  = dynamic_cast<MyItem*>(gylph);





A.    Thedynamic_cast ought to be a reinterpret_cast since the concrete type is unknown.

B.    The dynamic_cast is unnecessarysince we know that the concrete type returned by IWidgetSelector::Selection()must be a MyItem object.

C.    Thedynamic_cast is redundant, the programmer can invoke Activate directly,>Selection()->Activate();

D.    The dynamic_cast is necessary since we cannot know for certain whatconcrete type is returned by IWidgetSelector::Selection().

E.    Apolymorphic_cast should be used in place of the dynamic_cast.


【Q10】 Whichof the following identify const-correctness failures in the C++ program below?






MyArray(MyArray& copy);

MyArray& operator=(MyArray& copy);







MyData(MyArray<int>& x, MyArray<int>& y);


const MyArray<int>& x();

const MyArray<int>& y();



MyArray<int>read_data(int*, char**);

voidmake_changes(MyData* edit);


intmain(int argc, char* argv[])


const MyArray<int> read_x = read_data(&argc, argv);

const MyArray<int> read_y = read_data(&argc, argv);


MyData user_data(read_x, read_y);

MyData edit_buffer(user_data);




A.    MyData(MyArray<int>&x, MyArray<int>& y); should be

MyData(const MyArray<int>& x, const MyArray<int>& y);

B.    MyArray&operator=(MyArray& copy); should be

const MyArray& operator=(const MyArray& copy);

C.    voidmake_changes(MyData* edit); should be

void make_changes(const MyData* edit);

D.    MyArray(MyArray&copy); should be

MyArray(const MyArray& copy);

E.    constMyArray& operator=(const MyArray& copy); should be

const MyArray& operator=(const MyArray& copy) const;

【Q1】 In the givenC++ code snippet, which of the following statements correctly identify how Monof enum DOW can be assigned to a variable named var?



const int Mon = 1, Tue = 2;

enum DOW{ Mon = 11, Tue = 12 };



A.    Thevariable var will have to be of type enum DOW, and then defined as:

var = Mon;

B.    Mon of enum DOW cannotbe assigned because the compiler will give a redefinition error.

C.    Since enum DOW has beendeclared and defined later, it will be pushed onto the stack later, but will beaccessed first. Hence, the scope resolution operator is not required and varwill be assigned as:

var = Mon;

D.    SinceMon is of type enum DOW, var will be assigned as:

var = DOW::Mon;

E.    Thevariable var must be of type const int, and then it can be assigned as:

var = static_cast<const int>(Mon);


【Q2】 For the code snippetbelow, which of the following statements provide the correct order ofconstructor calls when object obj is created in main()?




Base(){cout << "In Base Ctor/n";


class Nest



Nest(){cout << "In Nest Ctor/n"; }




classDerive : public Base



Derive(){cout << "In Derive Ctor/n"; }








A.    Base constructor

Derive constructor

B.    Baseconstructor

Derive constructor

Nest constructor

C.    Baseconstructor

Nest constructor

Derive constructor

D.    Nestconstructor

Base constructor

Derive constructor

E.    Deriveconstructor

Base constructor

Nest constructor


【Q3】 The C++ codebelow generates a compiler error. Which of the following solutions can be usedto correctly access the member named nested?




int data;


class Nest



int nested;



static Nest* createNest(){return new Nest;}





SomeClass::Nest* nst = SomeClass::createNest();

nst->nested = 5;


A.    Make function voiduse_someclass() a friend of class SomeClass.

B.    Makethe function createNest() a non-static function of SomeClass.

C.    Declare the classNest in public scope of class SomeClass.

D.    Makethe object nst a reference object, and make the function createNest() return aNest&.

E.    Derive a class from SomeClass.Make the object nst a derived class pointer so that it can access SomeClass'sprotected declarations.


【Q4】 In C++, whichof the following statements regarding the code below are valid?





int m_o;


class Inner


int m_i;



Inner(Outer m_outer, int x)


m_outer.m_o = x;




Outer(int y)


m_inner.m_i = y;



void Display()


using namespace std;

cout << m_o << endl

<< m_inner.m_i << endl;


Inner m_inner;





Outer    objOut(10);

Outer::Inner objIn(objOut, 5);




A.    Theoutput will be:



B.    Outer class cannotaccess its nested class's private members.

C.    Therelationship between class Inner and class Outer is not valid C++ syntax.

D.    Innerclass cannot access its containing class's private members.

E.    Theoutput will be:




【Q5】 What is theoutput of the program below in C++?


usingnamespace std;





Object() {}


void Print() const


cout << "const"<< endl;



void Print()


cout << "mutable"<< endl;




voidprint_obj(const Object& obj)







Object       obj1;

const Object obj2;

Object*const pobj1 = &obj1;










return 0;



A.    const





B.    const





C.    mutable





D.    Undefinedbehavior

E.    Failsto compile


【Q6】 Which of thefollowing are possible outputs of the C++ code below?







void Print()


std::cout << "TestPrint" <<std::endl;



void Print() const


std::cout << "const TestPrint" <<std::endl;



void Print() volatile


std::cout << "volatile TestPrint"<< std::endl;



void Print() const volatile


std::cout << "const volatile TestPrint"<< std::endl;




intmain(int argc, char* argv[])


TestPrint normal_test;



const TestPrint const_test;



volatile TestPrint volatile_test;



const volatile TestPrint const_volatile_test;




A.    TestPrint

const TestPrint

const volatile TestPrint

const volatile TestPrint

B.    TestPrint

const volatile TestPrint

const volatile TestPrint

const volatile TestPrint

C.    TestPrint

const TestPrint

volatile TestPrint

const volatile TestPrint

D.    TestPrint




E.    TestPrint

const volatile TestPrint

volatile TestPrint

const volatile TestPrint


【Q7】 Which exceptionhandler will catch the exception throw by SomeFunction in C++?







classExDer:public ExBase{};



ExBase base;

throw base;









catch(ExDer& ex)


std::cout << "ExDer& handler/n";


catch(ExDer* ex)


std::cout << "ExDer* handler/n";


catch(ExBase& ex)


std::cout << "ExBase& handler/n";


catch(ExBase* ex)


std::cout << "ExBase* handler/n";




A.    ExBase& handler

B.    ExDer&handler

C.    ExBase*handler

D.    ExDer*handler

E.    Thecompiler will throw an ambiguity error as it will not able to determine whichcatch handler must be invoked.




应聘Morgan Stanley(转)

虽然应聘Morgan Stanley IT 已经告一段落了,但应聘过程中所经历的一切我想我永远都不会忘记,故写下此文,留作纪念。 【前言】        第一次听说Morgan Stanley 还是因...

刚做了Morgan Stanley IT部门Summer Intern的online test


【Morgan Stanley】AC面试

坐标上海,住了一宿,机票住宿费报销,公司很不错。 开始的时候大家在准备室,领取每个人的胸卡,然后拍照 之后半个小时算法笔试题,写代码 1、找出字符串中只出现一次的最靠前的字符 2、找出字符串中...

【Morgan Stanley IKM在线测试】C++

掌握好基础啊!>,>  考核内容包括不限于: 重构,重载,析构函数里(重构,重载,)new,malloc异常 堆和栈 OOP,OSI七层模型(应用层:http,ftp  传输层:tc...

热乎乎的morgan stanley 电面面经新鲜出炉~\(≧▽≦)/~啦啦啦

楼楼早上上午大概11点接到的电话,一个声音炒鸡好听的GG,说他是来自morgan stanley的,想和我约一下店面时间。我一听,真是戳不及防,掐指一算,online的IKE测试已经过去20几天了吧,...

【Morgan Stanley IT暑期实习生电面】

网上看到morgan招暑期实习生的消息,一直对大摩很是敬仰,虽做投行的大头,但是早就耳闻信息技术部丝毫不差。在网上做了很恶心的IKM测试,几天后就收到了来自上海的面试预约电话,然后就开始了一面。 全...

2015摩根士丹利(Morgan Stanley)实习电话面试

很荣幸接到了摩根电话面试的通知,做梦都没有想到,因为我笔试做的很烂,想着肯定被刷了,不知道为什么在我午睡的时候收到了预约电面的通知,迷迷糊糊,总之,很幸运。   面试我的面试官是一位中国人,很ni...

别人的Morgan Stanley面试,注重基础,java core、多线程、设计模式、设计程序。。。

过完年来就打算换工作,而是复习了1个月的基础做过的项目和英语。这个月的某天突然接到猎头的推荐,摩根斯坦利的direct hire职位,心中激动不已,抓紧复习英语,搜索了下ms的面试情况,全程都是英语面...

morgan stanley IT interview

I went to take part in morgan stanley IT interview this Friday afternoon in Bund Center. I wear my f...

Morgan Stanley(摩根士丹利)电面过程