c++ mutiple choice questions with answers

c++ mutiple choice questions with answers

 

1. How many types of polymorphisms are supported by C++?
A.     1    B.     2
C.     3    D.     4

Answer: Option B

Explanation:

The two main types of polymorphism are run-time (implemented as inheritance and virtual functions), and compile-time (implemented as templates).

    

2. How “Late binding” is implemented in C++?
A.     Using C++ tables
B.     Using Virtual tables
C.     Using Indexed virtual tables
D.     Using polymorphic tables

Answer: Option B

    

3.When are the Global objects destroyed?
A.     When the control comes out of the block in which they are being used.
B.     When the program terminates.
C.     When the control comes out of the function in which they are being used.
D.     As soon as local objects die.

Answer: Option B

    

4.Which of the following function prototype is perfectly acceptable?
A.     int Function(int Tmp = Show());
B.     float Function(int Tmp = Show(int, float));
C.     Both A and B.
D.     float = Show(int, float) Function(Tmp);

Answer: Option A

    

5.Which of the following statement is correct?
A.     A reference is stored on heap.
B.     A reference is stored on stack.
C.     A reference is stored in a queue.
D.     A reference is stored in a binary tree.

Answer: Option B

6.Which of the following statement is correct about the references?
A.     A reference must always be initialized within functions.
B.     A reference must always be initialized outside all functions.
C.     A reference must always be initialized.
D.     Both A and C.

Answer: Option C

7. What does C++ append to the end of a string literal constant?
A. a space
B. a number sign (#)
C. an asterisk (*)
D. a null character

Answer: option D

8.Null character needs a space of
A. zero bytes
B. one byte
C. three bytes
D. four bytes

Answer: option B

9.Which of the following formulas can be used to generate random integers between 1 and 10?
A. 1 + rand() % (10 – 1 + 1)
B. 1 + (10 – 1 + 1) % rand()
C. 10 + rand() % (10 – 1 + 1)
D. 10 + rand() % (10 + 1)

Answer: option A

10.The arguments that determine the state of the cout object are called
A. classes
B. manipulators
C. format flags or state flags
D. state controllers

Answer: option C

11.The statement int num[2][3]={ {1,2}, {3,4}, {5, 6} };
A. assigns a value 2 to num[1][2]
B. assigns a value 4 to num[1][2]
C. gives an error message
D. assigns a value 3 to num[1][2]

Answer: option C

12.Which of the following statement is correct about the program given below?

#include<iostream.h>
enum gvp
{
    a=1, b, c
};
int main()
{
    int x = c;
    int &y = x;
    int &z = x;
    y = b;
    cout<< z–;
    return 0;
}

A.     It will result in a compile time error.
B.     The program will print the output 1.
C.     The program will print the output 2.
D.     The program will print the output 3.

Answer: Option C

13.class Example{
    public: int a,b,c;
    Example(){a=b=c=1;} //Constructor 1
    Example(int a){a = a; b = c = 1;} //Constructor 2
    Example(int a,int b){a = a; b = b; c = 1;} //Constructor 3
    Example(int a,int b,int c){ a = a; b = b; c = c;} //Constructor 4
    }
    In the above example of constructor overloading, the following statement will call which constructor
    Example obj = new Example (1,2,3.3);

    A.Constructor 2

    B.Constructor 4

    C.Constrcutor 1

    D.Type mismatch error

    Answer: Constructor 4

14.Which of the following is not a standard exception built in C++.

    A.std::bad_creat

    B.std::bad_alloc

    C.std::bad_cast

    D.std::bad_typeid

    Answer: option A

15.Consider a linked list implemented of a queue with two pointers: front and rear.
  What is the time needed to insert element in a queue of length of n?

1) O(log2n)
2) O(n).
3) O(1).
4) O(n log2n).

16.What is the implicit pointer that is passed as the first argument for nonstatic member functions?
A. ‘self’ pointer
B. std::auto_ptr pointer
C. ‘Myself’ pointer
D. ‘this’ pointer

Ans: D

17. Which of the following is the most general exception handler that catches exception of any type?
A. catch(std::exception)
B. catch(std::any_exception)
C. catch(…)
D. catch()

Ans: C

18. Which of the following correctly describes the meaning of‘namespace’ feature in C++?
a. Namespaces refer to the memory space allocated for names used in a program
b. Namespaces refer to space between the names in a program
c. Namespaces refer to packing structure of classes in a program.
d. Namespaces provide facilities for organizing the names in aprogram to avoid name clashes.
Ans: d

19. If class A is friend of class B and if class B is friend of class C, which of the following is true?
a. Class C is friend of class A
b. Class A is friend of class C
c. Class A and Class C do not have any friend relationship
d. None of the above

 Ans: c

20.What is Latency time?
a.    Time taken by read/write head mechanism to position itself over appropriate cylinder
b.    Time taken to transfer a data from memory
c.    Time taken by appropriate sector to come under read/write head
d.    None of above
Ans: c

21.Who is father of C++ Language?

    Dr. E.F. Codd
    James A. Gosling
    Bjarne Stroustrup
    Dennis Ritchie

Answer : C

22.In how many ways is polymorphism achived in C++?

    2
    3
    1
    4

Answer : B

Explanation:

Operator overloading, Function overloading and Virtual function

23. we can access virtual function through the use of a…
    A.By pointer declaration to the base class
    B.By creating object to base class
    C.By creating object to sub class
    D.By creating friend class to base class

Answer: A

24.In context of C++ files. Select among the files which stream status bit indicates EOF?
   
a)     OxO4
b)     OxO3
c)     OxO2
d)     OxO1

Answer: D

25.What is meaning of following declaration?
    int(*ptr[5])();
a) ptr is pointer to function.
b) ptr is array of pointer to function.
c) ptr is pointer to such function which return type is array.
d) ptr is pointer to array of function.

Answer:b
Explanation:In this expression, ptr is array not pointer

26.Write the output of the following:
char *mychar; //points to memory location 1000
short *myshort; //points to memory location 2000
long *mylong //points to memory location 3000
mychar++;
++myshort;
mylong++;
cout << mychar << myshort << mylong;
A 1001 2001 3001
B 1001 2002 3004
C 1001 2001 3002
D 1001 2002 3004

 Ans: D
27.Value of a in a = (b = 5, b + 5); is
A Junk value
B Syntax error
C 5
D 10
Ans: D

28.If a member needs to have unique value for all the objects of that same class, declare the member as

A: Global variable outside class
B: Local variable inside constructor
C: Static variable inside class
D: Dynamic variable inside class

Ans:B

29. Which of the following cannot be inherited from the base class?

A: Constructor
B: Friend
C: Both a and b cannot be inherited
D: Both a and b can be inherited

Ans: C

32.Under what conditions a destructor destroys an object?

A: Scope of existence has finished
B: Object dynamically assigned and it is released using the operator delete.
C: Program terminated.
D: Both a and b.

Ans: D

33. What is deep copy?

A: A deep copy creates a copy of the dynamically allocated objects too.
B: A deep copy just copies the values of the data as they are.
C: A deep copy creates a copy of the statically allocated objects too
D: Both b and c above

Ans: A

34.  ios::ate is used for

A: Set the initial position at the end of the file.
B: Set the initial position at the start of the file.
C: Set the last position at the end of the file.
D: Set the last position at the start of the file.

Ans: A

35.What happens when a pointer is deleted twice?

A: It can abort the program
B: It can cause a failure
C: It can cause an error
D: It can cause a trap

Ans: D

36. What is shallow copy?

A: A shallow copy creates a copy of the dynamically allocated objects too.
B: A shallow copy just copies the values of the data as they are.
C: A shallow copy creates a copy of the statically allocated objects too
D: Both b and c above

Ans: B
37.Write the output of the following:
char *mychar; //points to memory location 1000
short *myshort; //points to memory location 2000
long *mylong //points to memory location 3000
mychar++;
++myshort;
mylong++;
cout << mychar << myshort << mylong;
A 1001 2001 3001
B 1001 2002 3004
C 1001 2001 3002
D 1001 2002 3004

 Ans: D

38.Value of a in a = (b = 5, b + 5); is
A Junk value
B Syntax error
C 5
D 10
Ans: D

39.If a member needs to have unique value for all the objects of that same class, declare the member as

A: Global variable outside class
B: Local variable inside constructor
C: Static variable inside class
D: Dynamic variable inside class

Ans:B

40. Which of the following cannot be inherited from the base class?

A: Constructor
B: Friend
C: Both a and b cannot be inherited
D: Both a and b can be inherited

Ans: C

41.Under what conditions a destructor destroys an object?

A: Scope of existence has finished
B: Object dynamically assigned and it is released using the operator delete.
C: Program terminated.
D: Both a and b.

Ans: D
42. What is deep copy?

A: A deep copy creates a copy of the dynamically allocated objects too.
B: A deep copy just copies the values of the data as they are.
C: A deep copy creates a copy of the statically allocated objects too
D: Both b and c above

Ans: A

43.  ios::ate is used for

A: Set the initial position at the end of the file.
B: Set the initial position at the start of the file.
C: Set the last position at the end of the file.
D: Set the last position at the start of the file.

Ans: A
44.What happens when a pointer is deleted twice?

A: It can abort the program
B: It can cause a failure
C: It can cause an error
D: It can cause a trap

Ans: D

45. What is shallow copy?

A: A shallow copy creates a copy of the dynamically allocated objects too.
B: A shallow copy just copies the values of the data as they are.
C: A shallow copy creates a copy of the statically allocated objects too
D: Both b and c above

Ans: B

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks