C++ Quiz



OOPS Quiz at csepedia.org

1. At which point of time a variable comes into existence in memory is determined by its

A. Scope
B. Storage class
C. Data type
D. All of the above


2. Consider the following statements

char *ptr;
ptr = "hello";
cout << *ptr;
What will be printed?

A. First Letter
B. Entire String
C. It is a Syntax Error
D. Last Letter


3. The keyword friend does not appear in

A. The class allowing access to another class
B. The class desiring access to another class
C. The private section of a class
D. The public section of a class


4. RunTime Polymorphism is achieved by ______

A. Friend function
B. Virtual function
C. Operator overloading
D. Function overloading


5. Which of the following declarations are illegal ?

A. void *ptr;
B. char *str = "hello";
C. char str = "hello";
D. const *int p1;


6. Consider the following statements:

int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?

A. 22
B. 37
C. 7
D. 5


7. In which case is it mandatory to provide a destructor in a class?

A. Almost in every class
B. Class for which two or more than two objects will be created
C. Class for which copy constructor is defined
D. Class whose objects will be created dynamically


8. What will be the value of c after the execution of the following statements?

int a, b, c;
a = 10;
b = 15;
c = ++a + b++;
cout<<c;

A. 25
B. 26
C. 27
D. Syntax Error


9. If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access

A. Protected and public data only in C and B
B. Protected and public data only in C
C. Private data in A and B
D. Protected data in A and B


10. A Copy Constructor takes

A. No argument
B. One argument
C. Two arguments
D. Arbitrary no. of arguments


11. Which can be passed as an argument to a function?

A. Constant
B. Expression
C. Another function
D. All of the above


12. A struct is the same as a class except that

A. There are no member functions
B. All members are public
C. Cannot be used in inheritance hierarchy
D. It does have a this pointer


13. A function call mechanism that passes arguments to a function by passing a copy of the values of the arguments is __________

A. Call by name
B. Call by value
C. Call by reference
D. Call by value result


14. What will be the output of the following program?

void main()
{
float x=5,y=2;
int result;
result=x % y;
cout<<result;
}

A. 1
B. 1.0
C. Error message
D. 2.5


15. Which of the statements are true ?

I. Function overloading is done at compile time.
II. Protected members are accessible to the member of derived class.
III. A derived class inherits constructors and destructors.
IV. A friend function can be called like a normal function.
V. Nested class is a derived class.

A. I, II, III
B. II, III, V
C. III, IV, V
D. I, II, IV


16. It is possible to declare as a friend

A. A Member Function
B. A Global Function
C. A Class
D. All of the above


17. Which of the following will produce a value 10 if x = 9.7 ?

A. floor(x)
B. abs(x)
C. log(x)
D. ceil(x)


18. If we create a file by ‘ifstream’, then the default mode of the file is

A. ios :: out
B. ios :: in
C. ios :: app
D. ios :: binary


19. A Pointer to the base class can hold address of

A. Only base class object
B. Only derived class object
C. Base class object as well as derived class object
D. None of the above


20. In C++, Dynamic Memory Allocation is accomplished with the operator ____

A. new
B. this
C. malloc()
D. delete




CSE Quiz

Algorithms




Database Management




C++ Quiz 1

C++ Quiz 2




Digital Electronics





Data Structures




Computer Architecture




Computer Network




HTML





Automata Theory




Operating System