Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » List of Companies » Morgan Stanely

Morgan Stanely C & C++ Interview Questions

First Round: Multiple Choice Questions
Round Two: 4 Programs on HackerRank

First Technical Round Via Online Test

Question 1:
Constructor can be defined under the access specifier:
A. Public
B. Private
C. Protected
D. All of above

Question 2:
If a static member variable is declared in the class then
A. In Constructor itself static member variable can initialized
B. It is required to implicitly declare the static member variable outside the class to allocate memory for it only once.
C. It is required to implicitly declare the static member variable outside the class to allocate memory for it, in every file the class is used.
D. At the time of instantiating the object memory is allocated of the static member variable also.

Question 3:
Difference between a Class and a structure is
A. Structure can not have member function
B. By default every member variables of structure are private
C. By default every member variables of structure are public
D. None of the above

Questoin 4:
Consider the following statements, which option is true in case of static functions
A. The function can access the private part of the class
B. The function is in the scope of the class
C. The function must be invoked on an object

Choose the answer
A & C
A & B
B & C
All of the above

Question 5:
Friend declaration
A. Must be in public part
B. Must be in private part
C. Can be in protected part but not in private part
D. Can be in the public or private part

Question 6:
Which option is true regarding this pointer
A. *this refers to object for which member function is invoked
B. In non static function, *this is a pointer to the object for which function was invoked
C. In non-const function of class X, the type of this is X* const
D. All of the above

Question 7:
Consider the following piece of code:-


void *ptr1;
char *ptr2;
ptr2 = ptr1;

which of the following statement is true -
A. It is valid if ptr1 is type casted to (char *)
B. Assignment of void pointer to char pointer is perfectly valid
C. It is not possible to assign a pointer type void is char
D. Both A & B work

Question 8:
Emp is a class In the following piece of code-


int main()
{
Emp E1;
Emp E2 = E1;
Emp E3; 
E3 = E2;
return 0;
}

A. Emp Constructor is called 3 times, Emp Destructor is called 3 times.
B. Emp Constructor is called 2 times, Emp Destructor is called 3 times.
C. Emp Constructor is called 3 times, Emp Destructor is called 2 times.
D. Emp Constructor is called 2 times, Emp Destructor is called 2 times.

Question 9.
In the following code-


#include<iostream.h>
int arr[10] = {};
int main()
{
for(int i=0; i<10; cout<< arr[i++]<<" ");
cout<<endl;
return 0;
}

A. array will be initialized to all zeros
B. All the elements will be having some random uninitialized
C. Depends upon the compiler
D. Except for the first element all the values will be initialized to zero

Question 10.


#include<iostream>

int fun(int);
int s = func(10);

int fun(int x)
{
    cout<<s;
    return (x+2*s);
}

int main()
{
cout<<fun(5);
return 0;
}

Considering the above code which statement given blow is TRUE:
A. Will give compilation error as initialized element (fun(10)) is not constant
B. It will give run time error
C. Will give output 10 5
D. Will give output 0 10 25

Question 11.
In Comparision of new and malloc which option of the following is correct
A. Unlike malloc(sizeof(Temp)), new Temp() calls Temp's constructor
B. new is an operator that can be overridden by a class, while malloc() is not overridden on a per-class
C. malloc() returns a void* which isn't type safe. new Temp() returns a pointer of the right type (a Type *)
D. All of the above

Question 12.
Which of the following statements about constant argument is correct
i. Const qualifier tell compiler that the function should not modify the arguments
ii. Const argument declarations significant when arguments are passed by reference, pointer or value
iii. Const argument declaration is significant only when arguments are passed by reference or pointer
iv. If the argument is pass by value and if the value or argument is changed then it is compiler dependent whether it will give error or a warning
A. i & ii
B. i, iii & iv
C. i & iv
D. i, ii & iv

Question 13.
In the case of Run time polymorphism
A. Function is called based on the type of reference
B. Function is called based on the type object
C. Function is called based on the type of parameters
D. Function is called on the type of pointer

Question 14.
Which of the following statement is correct in case of Template functions
A. template function can be overloaded with the template function or with a ordinary function
B. if a template function overloaded depends on the number of parameters not the type of parameters
C. template function can be overloaded by a template function
D. template functions can not be overloaded

Question 15.
If the following statement is present in any code, what will be the behavior:


strcat("Hi", "there");

A. It will compile and work perfectly
B. It will compile but give segmentation fault
C. It will compile but give error at linking time
D. The problem will be with "there" rather then with "Hi"

Question 16.
Given a piece of code identify the correct statement-


class Temp
{
private: int x;
public:  
        int GetX();
        int GetY();
private: int y;
public: 
        int printx(int);
};

A. Access specifier can be defined as many times in a class as you require
B. Access specifier can defined as many time in the case of public only
C. Once one access specifier is defined it can not be defined in the same class
D. Access specifier can be defined only once if it is a base class, if the class is a derived class then it can have as many times it requires.

Question 17.
If class A is a base class and Class B & C are derived from it, then class D is derived from class B & C. To avoid multiple copies of data in class D.
A. Class D needs to be inherited as virtual
B. Class B & C needs to be inherited as virtual
C. Class A should be a virtual base class
D. Class A should be a container class

Question 18.
If B is a class and class D is derived from class B, and there is a public member function on B, and there is a public member function on B - f(int a, int b) then according to the following code


class D: private B
{
public: 
    B::f;
}

A. If the inheritance is public then only the function f() can become public class B
B. Will give compilation error
C. Will make the function f() as public in class D
D. If inheritance is private then by no means any derived function can come to public access specifier in the derived class i.e class D

Question 19.
Look at the following piece of code


#include
int main()
{
std::cout<<" Enter numbers separated by whitespace (use -1 to quit):";
int i = 0;

while(i!=-1)
{
std::cin>>i;
std::cout<<"You entered "<< i << '\n';
}
return 0;
}

A. Code will give compilation error
B. Code will compile and will be terminated as soon as non int value is given
C. Code will compile and will go to infinite loop as soon as non int value is given
D. Code will compile but, will give run time error

Second Technical Interview on HackerRank

3 C/C++ program on HackerRank
1 Database query on HackerRank