C++ Questions

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 31

C++ Questions & Answers JECRC UNIVERSITY JAIPUR

SET-1
1. Which of the following type of class allows only one object of it to be created?
A. Virtual class
B. Abstract class
C. Singleton class
D. Friend class

Answer: Option C

2. Which of the following is not a type of constructor?


A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor

Answer: Option B

3. Which of the following statements is correct?


A. Base class pointer cannot point to derived class.
B. Derived class pointer cannot point to base class.
C. Pointer to derived class cannot be created.
D. Pointer to base class cannot be created.

Answer: Option B

4. Which of the following is not the member of class?


A. Static function
B. Friend function
C. Const function
D. Virtual function

Answer: Option B

5. Which of the following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading

Answer: Option C
6. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function

Answer: Option B

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
7. Which of the following concept of oops allows compiler to insert arguments in a function call if it is
not specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer

Answer: Option C

8. How many instances of an abstract class can be created?


A. 1
B. 5
C. 13
D. 0

Answer: Option D

9. Which of the following cannot be friend?


A. Function
B. Class
C. Object
D. Operator function

Answer: Option C

10. Which of the following concepts of OOPS means exposing only necessary information to client?
A. Encapsulation
B. Abstraction
C. Data hiding
D. Data binding

Answer: Option C

11. Why reference is not same as a pointer?


A. A reference can never be null.
B. A reference once established cannot be changed.
C. Reference doesn't need an explicit dereferencing mechanism.
D. All of the above.

Answer: Option D
12. cout is a/an __________ .
A. operator
B. function
C. object
D. macro

Answer: Option C

13. Which of the following concepts provides facility of using object of one class inside another class?
A. Encapsulation

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
B. Abstraction
C. Composition
D. Inheritance

Answer: Option C

14. How many types of polymorphisms are supported by C++?


A. 1
B. 2
C. 3
D. 4

Answer: Option B

15. Which of the following is an abstract data type?


A. int
B. double
C. string
D. Class

Answer: Option D

16. Which of the following concepts means adding new components to a program as it runs?
A. Data hiding
B. Dynamic typing
C. Dynamic binding
D. Dynamic loading

Answer: Option D

17. Which of the following statement is correct?


A. A constructor is called at the time of declaration of an object.
B. A constructor is called at the time of use of an object.
C. A constructor is called at the time of declaration of a class.
D. A constructor is called at the time of use of a class.

Answer: Option A

18. Which of the following correctly describes overloading of functions?


A. Virtual polymorphism
B. Transient polymorphism
C. Ad-hoc polymorphism
D. Pseudo polymorphism

Answer: Option C

19. Which of the following approach is adapted by C++?


A. Top-down
B. Bottom-up
C. Right-lef
D. Lef-right

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR

Answer: Option B

20. Which of the following is correct about function overloading?


A. The types of arguments are different.
B. The order of argument is different.
C. The number of argument is same.
D. Both A and B.

Answer: Option D
21.Which of the following is correct about class and structure?
A. class can have member functions while structure cannot.
B. class data members are public by default while that of structure are private.
C. Pointer to structure or classes cannot be declared.
D. class data members are private by default while that of structure are public by default.

Answer: Option D
22. Which of the following concepts means wrapping up of data and functions together?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism

Answer: Option B

23.Which of the following concepts means waiting until runtime to determine which function to call?
A. Data hiding
B. Dynamic casting
C. Dynamic binding
D. Dynamic loading

Answer: Option C

24.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

25.Which of the following operator is overloaded for object cout?


A. >>
B. <<
C. +
D. =

Answer: Option B
26. Which of the following is the correct class of the object cout?
A. iostream
B. istream

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
C. ostream
D. ifstream

Answer: Option C

27.Which of the following cannot be used with the keyword virtual?


A. class
B. member functions
C. constructor
D. destructor

Answer: Option C

28.Which of the following functions are performed by a constructor?


A. Construct a new class
B. Construct a new object
C. Construct a new function
D. Initialize objects

Answer: Option D

29.Which of the following problem causes an exception?


A. Missing semicolon in statement in main().
B. A problem in calling function.
C. A syntax error.
D. A run-time error.

Answer: Option D

30.Which one of the following options is correct about the statement given below? The compiler
checks the type of reference in the object and not the type of object.
A. Inheritance
B. Polymorphism
C. Abstraction
D. Encapsulation

Answer: Option B
31.Which of the following is the correct way of declaring a function as constant?
A. const int ShowData(void) { /* statements */ }
B. int const ShowData(void) { /* statements */ }
C. int ShowData(void) const { /* statements */ }
D. Both A and B

Answer: Option C

32.Which of the following concepts is used to implement late binding?


A. Virtual function
B. Operator function
C. Const function
D. Static function

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
Answer: Option A

33.Which of the following statement is correct?


A. C++ allows static type checking.
B. C++ allows dynamic type checking.
C. C++ allows static member function be of type const.
D. Both A and B.

Answer: Option D

34.Which of the following factors supports the statement that reusability is a desirable feature of a
language?
A. It decreases the testing time.
B. It lowers the maintenance cost.
C. It reduces the compilation time.
D. Both A and B.

Answer: Option D

35.Which of the following ways are legal to access a class data member using this pointer?
A. this->x
B. this.x
C. *this.x
D. *this-x

Answer: Option A

36. Which of the following is a mechanism of static polymorphism?


A. Operator overloading
B. Function overloading
C. Templates
D. All of the above

Answer: Option D

37.Which of the following is correct about the statements given below?

All operators can be overloaded in C++.


We can change the basic meaning of an operator in C++.

A. Only I is true.
B. Both I and II are false.
C. Only II is true.
D. Both I and II are true.

Answer: Option B

38.What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.
B. Only base class function will get called irrespective of object.

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
C. Only derived class function will get called irrespective of object.
D. Base class object will call base class function and derived class object will call derived class
function.

Answer: Option D

39.Which of the following are available only in the class hierarchy chain?
A. Public data members
B. Private data members
C. Protected data members
D. Member functions

Answer: Option C

40.Which of the following is not a type of inheritance?


A. Multiple
B. Multilevel
C. Distributive
D. Hierarchical

Answer: Option C
41. Which of the following operators cannot be overloaded?
A. []
B. ->
C. ?:
D. *

Answer: Option C

42. In which of the following a virtual call is resolved at the time of compilation?
A. From inside the destructor.
B. From inside the constructor.
C. From inside the main().
D. Both A and B.

Answer: Option D

43. Which of the following statements regarding inline functions is correct?


A. It speeds up execution.
B. It slows down execution.
C. It increases the code size.
D. Both A and C.

Answer: Option D

44. Which one of the following is the correct way to declare a pure virtual function?
A. virtual void Display(void){0};
B. virtual void Display = 0;
C. virtual void Display(void) = 0;
D. void Display(void) = 0;

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
Answer: Option C

45. Which of the following header file includes definition of cin and cout?
A. istream.h
B. ostream.h
C. iomanip.h
D. iostream.h

Answer: Option D
46. Which of the following keyword is used to overload an operator?
A. overload
B. operator
C. friend
D. override

Answer: Option B

47. What will happen if a class is not having any name?


A. It cannot have a destructor.
B. It cannot have a constructor.
C. It is not allowed.
D. Both A and B.

Answer: Option D

48. Which inheritance type is used in the class given below?


class A : public X, public Y
{}
A. Multilevel inheritance
B. Multiple inheritance
C. Hybrid inheritance
D. Hierarchical Inheritance

Answer: Option B

49. Which one of the following is correct about the statements given below?

All function calls are resolved at compile-time in Procedure Oriented Programming.


All function calls are resolved at compile-time in OOPS.

A. Only II is correct.
B. Both I and II are correct.
C. Only I is correct.
D. Both I and II are incorrect.

Answer: Option C

50. Which of the following is an invalid visibility label while inheriting a class?
A. public
B. private

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
C. protected
D. friend

Answer: Option D

51. Which one of the following options is correct?


A. Friend function can access public data members of the class.
B. Friend function can access protected data members of the class.
C. Friend function can access private data members of the class.
D. All of the above.

Answer: Option D

52. Which of the following statements is correct in C++?


A. Classes cannot have data as protected members.
B. Structures can have functions as members.
C. Class members are public by default.
D. Structure members are private by default.

Answer: Option B

53. Which of the following is used to make an abstract class?


A. Declaring it abstract using static keyword.
B. Declaring it abstract using virtual keyword.
C. Making at least one member function as virtual function.
D. Making at least one member function as pure virtual function.

Answer: Option D

54. Which of the following access specifier is used as a default in a class definition?
A. protected
B. public
C. private
D. friend

Answer: Option C

55. What is correct about the static data member of a class?


A. A static member function can access only static data members of a class.
B. A static data member is shared among all the object of the class.
C. A static data member can be accessed directly from main().
D. Both A and B.

Answer: Option D

56. Which of the following provides a reuse mechanism?


A. Abstraction
B. Inheritance
C. Dynamic binding
D. Encapsulation

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
Answer: Option B

57. Which of the following statement is correct?


A. Class is an instance of object.
B. Object is an instance of a class.
C. Class is an instance of data type.
D. Object is an instance of data type.

Answer: Option B

SET-2
1) Procedure oriented Programs are called as
A Structured programming
B Object oriented programming
C Functional programming
D None of the above

2)A _____________ is a class whose instances themselves are classes.


Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)
C++ Questions & Answers JECRC UNIVERSITY JAIPUR
A subclass
B abstarct class
C metaclass
D object class

3)_______________ enables you to hide, inside the object, both the data fields and the methods
that act on that data.
A Encapsulation
B Polymorphism
C Inheritance
D Overloading

4)For a 16 bit word length Integer data type values lie between ________________
A 32768 to 32767.
B 0 to 32767
C -128 to 128
D 0 to 128

5)The __________ operator is known as insertion operator


A >>
B >
C <<
D <

6)Which of the following is NOT a Relational Operator


A ==
B >
C %
D !=

7)A __________ is an abstract idea that can be represented with data structures and functions.
A class
B object
C loop
D data type

8)Automatic Initialization of object is carried out using a special member function called
____________________
A friend
B casting
C reference parameter
D constructor.

9)A class can allow non-member functions and other classes to access its own private data, by
making them as _________________.
A private
B protected
C Friend
D public

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
10)____________________ is the process of creating new classes, called derived classes, from
existing classes called base class
A Inheritance
B encapsulation
C Polymorphism
D overloading

11)A ___________ class can share selected properties of its base classes,
A abstarct
B derived
C subclass
D both b & c

12)A _______________ is the address of a memory location and provides an indirect way of
accessing data in memory.
A Constant
B variable
C Pointer
D object

13)To perform identical operations for each type of data compactly and conveniently we have to use
A Exception
B constant parameter
C function templates
D None of the above

14)_____________ function writes a string of text to a window.


A cputs ( )
B put ()
C gets ()
D tputs ()

15)In graphics mode the basic element is a __________


A character
B text
C table
D pixel

16)The ________________ objects have values that can be tested for various error conditions.
A osstream
B ofstream
C stream
D ifstream

17)Which function return the current position of the get or put pointer in bytes.
A tellg ()
B tellp ()
C tell ()
D Both A and B

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
18)________________ is a technique that allows the user considerable flexibility in the way the
programs are used
A Redirection
B manipulation
C Detecting
D None of the above

19)Operator such as ______________ cannot be overloaded.


A +
B ++
C ::
D ==

20)In c++ ___________ Operator is used for Dynamic memory allocation


A Scope resolution
B Conditional
C New
D Membership access

21)The advantages of OOP are , 1. increased programming productivity 2. decreased maintenance


costs. 3. less time to execute 4. easy to understand
A 1& 3
B 1& 2
C 3& 4
D 2& 3

22)Find the Hierarchy Of Data Types 1. Long double 2. Double 3. Float 4. Long 5. Int 6. Char
A 1-2-3-4-5-6
B 1-3-2-4-5-6
C 1-2-3-5-4-6
D 1-2-4-3-5-6

23)State True or False 1. A static member function cannot be declared virtual, whereas a non-static
member functions can be declared as virtual 2. A static member function cannot have access to the
'this' pointer of the class.
A 1-T,2-F
B 1-F,2-T
C 1-T,2-T
D 1-F,2-F

24)State True or False 1. The this pointer is used as a pointer to the class object instance by the
member function. 2. By using polymorphism, you cannot create new objects that perform the same
functions as the base object
A 1-T,2-F
B 1-T,2-T
C 1-F,2-F
D 1-T,2-T

25)Which functions return the maximum pixels in each row (number of columns) and each column
(number of rows) of the screen
A getmar() and getmac()

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
B maxx() and maxy()
C getmaxx() and getmaxy()
D getmayy() and getmaxy()

26)what does this program do # include <fstream.h> void main() { const int max = 80; char buffer[80];
ifstream infile ("out.txt"); while (infile) { infile.getline(buffer,max); cout << buffer; } }
A check a ACII charcter in a File.
B reads an String File.
C reads an Ascii String File.
D check a String File.

27)Find the output of the following program #include <iostream.h> Void main () { int age=15; if (age
> 12 && age < 20) cout<<You are a teen-aged person; else cout<<You are not teen-aged; }
A 15
B You are a teen-aged person
C 20
D You are not teen-aged

28)The first index number in an array starts with _________ and the last index number of an array of
size n will be ______
A 0 & n-1
B 1 & n-1
C 0&n
D 1&n

29)State True or False 1. Public data members can be accessed directly in the main function without
an object. 2. Constructors can be overloaded.
A 1-F, 2-F
B 1-F, 2-T
C 1-T, 2-T
D 1-T, 2-F
To overload an operator _____________keyword must be used along with the operator to be
overloaded.
30)To overload an operator _____________keyword must be used along with the operator to be
overloaded.
A Over
B Overload
C void
D Operator

31)Which one of the following declaration is invalid?


A int a[];
B int a[]={19, 21, 16, 1, 50};
C int a[5]={19, b, 16, c, 50};
D int a[5];

32) Define the relationshiphttp://i2.wp.com/www.jbigdeal.com/wp-


content/uploads/2013/07/Pic.jpg
A 1-is-a, 2. part-of 3.a-kind-of

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
B 1-is-a, 2.a-kind-of 3. Part-of
C 1 a-kind-of-2.is-a,3. Part-of
D None of the above

33)What is the output of the program # include <iostream.h> void main() { int n=1; cout
<<endl<<"The numbers are ;"<<endl; do { cout <<n<<"\t"; n++; } while (n<=100); cout<<endl; }
A print natural numbers 0 to 99
B print natural numbers 1 to 99
C print natural numbers 0 to 100
D print natural numbers 1 to 100

34)What is the output of the program # include <iostream.h> class counter { private : int count;
public : counter() { count = 0; cout<<"New Object Created\n"; } void inc_count () { count++; } int
getcount() { return count; } ~counter() { cout<<"One Object Deleted\n" ; } }; void main() { counter
c1,c2; }Output:
A New Object Created New Object Created One Object Deleted
B New Object Created New Object Created
C New Object Created One Object Deleted
D New Object Created New Object Created One Object Deleted One Object Deleted

35)What is the output of the program class Window // Base class for C++ virtual function example
{ public: virtual void Create() { cout <<"Base class Window"<<endl; } }; class CommandButton : public
Window { public: void Create() { cout<<"Derived class Command Button "<<endl; } }; void main()
{ Window *x, *y; x = new Window(); x->Create(); y = new CommandButton(); y->Create(); }
A Base class Window
B Base class Window Derived class Command Button
C Derived class Command Button
D ERROR

36)What is the output of the program #include <iostream.h> template <class T, int N> class array { T
memblock [N]; public: void setmember (int x, T value); T getmember (int x); }; template <class T, int
N> array<T,N>::setmember (int x, T value) { memblock[x]=value; } template <class T, int N> T
array<T,N>::getmember (int x) { return memblock[x]; } int main () { array <int,5> myints; array
<float,5> myfloats; myints.setmember (0,100); myfloats.setmember (3,3.1416); cout <<
myints.getmember(0) << '\n'; cout << myfloats.getmember(3) << '\n'; return 0; }
A 100 3.1416
B syntax error
C 100
D No output

37)What is the use of the this program # include <fstream.h> void main() { ofstream tstfile
("out.dat"); char text[ ] = "This is a text line"; int i=0; while (text[i]) tstfile. put(text[i++]); }
A to create a file
B to print a text on monitor
C to read a file
D None of the above

38)In the below Declaration how many copies of x does DC inherits ? Class BC { Private: int x; }; Class
BC1: virtual public BC { Private : Float y; }; Class BC2: virtual public BC { Private: float z; }; Class DC:
public BC1, Public Bc2 { };
A One

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
B Two
C Zero

39) The objects are ....... if all their attribute values are identical ?
A Identical
B Distinct
C Same
D None
40) Object is....... ?
A A concept
B Abstraction
C Thing
D All of above

41) The mechanism by which the data and functions are bound together with an object definition ?
A Inheritance
B Abstraction
C Polymorphism
D Encapsulation

42) The process of creating instances from classes ?


A Integrity
B Instantation
C Inheritance
D Generalization

43) Override is a method .... ?


A For an operation that replaces an inherited method for the same operatio
B For a data that replaces an inherited method for the same operation
C For an operation that takes argument from library function
D None of these

44) In C++, a function contained with in a class is called ?


A In built functio
B User defined function
C Member function
D None of these

45) In C++, setw is..... ?


A Initialization Operato
B Conditional Operator
C Memory allocation Operator
D Field with Operator

46) A template can be used to create a family of ?


A Classe
B Functions
C Class and function
D None of these

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
47) In C++, we can use the same function name to create functions that perform a variety of
different tasks. This is known as ?
A Global function
B Function overloading
C Inheritance
D All of above

48) Which of the following is an object oriented programming ?


A Real time syste
B AI and expert systems
C Neural networks and parallel programming
D All of above

49) Function overloading is a type of


A polymorphism
B inheritance
C classes
D data hiding

50) By-default members of a class are-


A private
B public
C both
D none of above

Answer Key-
1 A
2 C
3 A
4 A
5 C
6 C
7 A
8 D
9 C
10 A
11 D
12 C
13 C
14 A
15 D
16 D
17 B
18 A
19 C
20 C
21 B
22 A

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
23 C
24 A
25 C
26 C
27 B
28 A
29 B
30 D
31 C
32 C
33 D
34 D
35 B
36 A
37 A
38 A
39 C
40 D
41 D
42 A
43 B
44 D
45 C
46 A
47 D
48 B
49 A
50 A

SET-3 and SET-4


1. If the class name is X, what is the type of its this pointer (in a nonstatic, non-const member
function)?
a. const X* const
b. X* const
c. X*
d. X&

2. Which classes allow primitive types to be accessed as objects?


a. Storage
b. Virtual
c. Friend
Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)
C++ Questions & Answers JECRC UNIVERSITY JAIPUR
d. Wrapper

3. When is std::bad_alloc exception thrown?


a. When new operator cannot allocate memory
b. When alloc function fails
c. When type requested for new operation is considered bad, thisexception is thrown
d. When delete operator cannot delete teh allocated (corrupted) object

4. Which one of the following is not a fundamental data type in C++


a. float
b. string
c. int
d. wchar_t

5. Which of the following is a valid destructor of the class name "Country"


a. int ~Country()
b. Country()
c. int ~Country(Country obj)
d. ~Country()

6. Which of the following correctly describes C++ language?


a. Statically typed language
b. Dynamically typed language
c. Both Statically and dynamically typed language
d. Type-less language

7. Which of the following keyword supports dynamic method resolution?


a. abstract
b. Virtual
c. Dynamic
d. Typeid

8. Which of the following is the most preferred way of throwing and handling exceptions?
a. Throw by value and catch by reference.
b. Throw by reference and catch by reference.
c. Throw by value and catch by value
d. Throw the pointer value and provide catch for teh pointer type.

9. Which of the following is not true about preprocessor directives


a. They begin with a hash symbol
b. They are processed by a preprocessor
c. They form an integral part of the code
d. They have to end with a semi colon

10. What's wrong? while( (i < 10) && (i > 24))


a. the logical operator && cannot be used in a test condition
b. the while loop is an exit-condition loop
c. the test condition is always false
d. the test condition is always true

11. A continue statement causes execution to skip to

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
a. the return 0; statement
b. the first statement afer the loop
c. the statement following the continue statement
d. the next iteration of the loop

12. What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);


a. the question mark should be an equal sign
b. the first semicolon should be a colon
c. there are too many variables in the statement
d. the conditional operator is only used with apstrings

13. What's wrong? for (int k = 2, k <=12, k++)


a. the increment should always be ++k
b. the variable must always be the letter i when using a for loop
c. there should be a semicolon at the end of the statement
d. the commas should be semicolons

14. Which of the following is not recommended in a header file?


a. Type definitions (typedefs)
b. Class definitions
c. Function definitions
d. Template definitions

15. Which of the STL containers store the elements contiguously (in adjecent memory locations)?
a. std::vector
b. std::list
c. std::map
d. std::set

16. 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

17. What does STL stand for?


a. Simple Template Library
b. Standard Template Library
c. Static Type Library
d. Single Type-based Library

18. What is the difference between overloaded functions and overridden functions?
a. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
b. Redefining a function in a friend class is called function overriding while Redefining a function in a
derived class is called a overloaded fucntion.
c. Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding
d. Redefining a function in a friend class is called function overloading while Redefining a function in
a derived class is called as overridden fucnion.

19. Which one of the following is not a valid reserved keyword in C++
a. Explicit

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
b. Public
c. Implicit
d. Private

20. Each pass through a loop is called a/an


a. enumeration
b. iteration
c. culmination
d. pass through

21. Which of the following is true about const member functions?


a. const members can be invoked on both const as well as nonconst objects
b. const members can be invoked only on const objects and not on nonconst objects
c. nonconst members can be invoked on const objects as well as nonconst objects
d. none of the above

22. Which of the following relationship is known as inheritancerelationship?


a. has-a relationship
b. is-a relationship
c. association relationship
d. none of the

23. 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

24. A direct access file is:


a. A file in which recoreds are arranged in a way they are inserted in a file
b. A file in which records are arranged in a particular order
c. Files which are stored on a direct access storage medium
d. None of the above

25. Which of the following is not a component of file system


a. Access method
b. Auxiliary storage management
c. Free integrity mechanism
d. None of the above
26. Seek time is
a. time taken to retrieve a dta
b. Time taken by read/write head mechanism to position itself over appropriate cylinder
c. Time taken by appropriate sector to come under read/write
d. None of the above

27. Prime area in context of file system is defined as


a. It is memory area created by operating system
b. It is an area into which data records are written
c. It is the main area of a web page
d. None of the above

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
28. In mulit-list organization
a. Records that have equivalent value for a given secondary index item are linked together to form a
list.
b. Records are loaded in ordered sequence defined by collating sequence by content of the key
c. Records are directly accessed by record key field
d. None of the above

29. Which of the following is/are advantages of cellular partitioned structure:


a. Simultaneous read operations can be overlapped
b. Search time is reduced
c. Both a & b
d. None of the above

30. *ptr++ is equivalenet to:


a. ptr++
b. *ptr
c. ++*ptr
d. None of the above

31. The conditional compilation


a. It is taken care of by the compiler
b. It is setting the compiler option conditionally
c. It is compiling a program based on a condition
d. none of above

32. Originally C was developed as:


a. System programming language
b. General purpose language
c. Data processing language
d. None of above

33. An inverted file


a. Locates information about data in small files that are maintained apart from actual data record
b. A file which stores opposite records
c. A file which stores information about records of a system
d. None of above

34. Which of the following is not a file operation:


a. Repositioning
b. Truncating
c. Appending
d. None of above

35. Latency time is:


a. Time taken by read/write head mechanism to position itself over appropriate cylinder
b. Time taken to transfer a dta from memory
c. Time taken by appropriate sector to come under read/write head
d. None of above

36. The two types of file structure existing in VSAM file are
a. Key sequenced structure, entry sequenced structure

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
b. Key sequence structure, exit sequenced structure
c. Entry sequence structure, exit sequenced structure
d. None of above

37. How many copies of a class static member are shared between objects of the class?
a. A copy of the static member is shared by all objects of a class
b. A copy is created only when at least one object is created from that class
c. A copy of the static member is created for each instntiation of the class
d. No memory is allocated for static members of a class

38. Which looping process checks the test condition at the end of the loop?
a. for
b. while
c. do-while
d. no looping process checks the test condition at the end

39. The default access level assigned to members of a class is ___________


a. Private
b. Public
c. Protected
d. Needs to be assigned

40. Which of the following correctly describes the meaning ofnamespace 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.

41. 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 teh names in a program
c. Namespaces refer to space between the names in a program
d. namespaces provide facilities for organizing the names in a program to avoid name clashes

42. Which of the following language is not supported by C++?


a. Exception Handling
b. Reflection
c. Operator Overloading
d. Namespaces
43. class derived: public base1, public base2 { } is an example of
a. Polymorphic inheritance
b. Multilevel inheritance
c. Hierarchical inheritance
d. Multiple inheritance

44. Which of the following languages is a subset of C++ language?


a. C language
b. Java Language
c. C# language
d. language

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
45. How do we declare an interface class?
a. By making all the methods pure virtual in a class
b. By making all the methods abstract using the keyword abstract in a class
c. By declaring the class as interface with the keyword interface
d. It is not possible to create interface class in C++

46. How do we declare an abstract class?


a. By providing at least one pure virtual method (function signature followed by ==0;) in a class
b. By declaring at least one method abstract using the keyword abstract in a class
c. By declaring the class abstract with the keyword abstract
d. It is not possible to create abstract classes in C++

47. Which of the following is not an advantage of secondary memory


a. It is cost-effective
b. It has large storage capacity
c. It has highest speed
d. It is easily portable

48. 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

49. Which of the following language feature is not an access specifier in C++?
a. public
b. private
c. C protected
d. internal

50. Expression C=i++ causes


a. Value of i assigned to C and then i incremented by 1
b. i to be incremented by 1 and then value of i assigned to C
c. Value of i assigned to C
d. i to be incremented by 1

51. The statement i++; is equivalent to


a. i = i + i;
b. i = i + 1;
c. i = i - 1;
d. i --;

52. In C language, a hexadecimal number is represented by writing


a. x
b. xo
c. ox
d. h

53. Which of the following library function below by default aborts the program?
a. Terminate()
b. end()

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
c. Abort()
d. exit()

54. 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

55. Value of ix+j, if i,j are integer type and ix long type would be
a. integer
b. float
c. long integer
d. double percision

56. Which of the following below can perform conversions between pointers to related classes?
a. A. cast_static
b. B. dynamic_cast
c. c. static_cast
d. D. cast_dynamic

57. How do we define a constructor?


a. a. x~() {}
b. B. X() {}~
c. C. X() ~{}
d. D. ~X() {}

58. Vtables
a. creates a static table per class
b. creates a static table per object
c. creates a dynamic table per class
d. creates a dynamic table per object

59. When class B is inherited from class A, what is the order in which the constructers of those
classes are called
a. Class A first Class B next
b. Class B first Class A next
c. Class B's only as it is the child class
d. Class A's only as it is the parent class

60. 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()

61. 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)

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
c. catch()
d. catch()

62. In a group of nested loops, which loop is executed the most number of times?
a. the outermost loop
b. the innermost loop
c. all loops are executed the same number of times
d. cannot be determined without knowing the size of the loops

63. What is the Difference between struct and class in terms of Access Modifier?
a. By default all the struct members are private while by default class members are public.
b. By default all the struct members are protected while by default class members are private.
c. By default all the struct members are public while by default class members are private.
d. By default all the struct members are public while by default class members are protected.

64. Inline functions are invoked at the time of


a. Run time
b. Compile time
c. Depends on how it is invoked
d. Both b and c above

65. 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

66. 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

67. Which of the following below is /are a valid iterator type?


a. Input Iterator
b. Backward Iterator
c. Forward Iterator
d. Both a and c above

68. What defines a general set of operations that will be applied to various types of data?
a. Template class
b. Function template
c. Class template
d. Both a and c above

69. Under which of the following circumstances, synchronization takes place?


a. When the file is closed
b. When the buffer is empty
c. Explicitly, with manipulators
d. both a and c

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
70. Which of the following functions below can be used Allocate space for array in memory?
a. calloc()
b. malloc()
c. Realloc()
d. both a and b

71. Statement scanf(%d,80);


a. Assign an integer to variable i
b. Give an error message
c. Print the value of i
d. Assign an float to variable i

72. STL is based on which of the following programming paradigms?


a. Structured Programming
b. Object Oriented Programming (OOP)
c. Functional Programming
d. Aspect Oriented Programming (AOP)

73. STL is based on which of the following programmingparadigms?


a. Structured Programming
b. Object Oriented Programming (OOP)
c. Functional Programming
d. Aspect Oriented Programming (AOP)

74. If there is more than one statement in the block of a for loop, which of the following must be
placed at the beginning and the ending of the loop block?
a. parentheses ( )
b. braces { }
c. brackets [ ].
d. arrows < >

75. Which of the following members do get inherited but become private members in child class
a. Public
b. Private
c. Protected
d. All the above

76. Which looping process is best used when the number of iterations is known?
a. for
b. while
c. do-while
d. all looping processes require that the iterations be known

77. In a C language 3 represents


a. A digit
b. An integer
c. A character
d. A word

78. Which of the following is the most common way of implementing C++?
a. C++ programs are directly compiled into native code by a compiler

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
b. C++ programs are first compiled to intermediate code by a compiler and then executed by a virtual
machine
c. C++ programs are interpreted by an interpreter
d. A C++ editor directly compiles and executes the program

79. Which header file should we include for using std::auto_ptr?


a. <memory>
b. <alloc>
c. <autoptr>
d. <smartptr>

80. Which of the following operators can be implemented as a nonmember operator?


#NAME?
b. () (function call operator)
c. [. (array access operator)
d. + (addition operator)

81. 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

82. Which of the following operators can be overloaded?


a. . (dot or member access operator)
b. & (address-of operator)
c. sizeof operator
d. ?: (conditional operator)

83. Which of the following operator cannot be overloaded?


#NAME?
b. == (equality operator)
c. > (row operator)
d. :: (cope resolution operator)

84. Which of the following operators below allow to define the member functions of a class outside
the class?
a. ::
b. ?
c. :?
d. %

85. Which of the following is not a valid conditional inclusions in preprocessor directives
a. #ifdef
b. #ifundef
c. #endif
d. #elif

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


a. std::bad_creat
b. std::bad_alloc

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
c. std::bad_cast
d. std::bad_typeid

87. 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

88. Under which of the following circumstances, synchronization takes place?


a. When the file is closed
b. When the buffer is empty
c. Explicitly, with manipulators
d. both a and c

89. Which of the following functions below can be used Allocate space for array in memory?
a. calloc()
b. malloc()
c. Realloc()
d. both a and b

90. Which of the following is not a valid conditional inclusions in preprocessor directives
a. #ifdef
b. #ifundef
c. #endif
d. #elif

91. Value of a in a = (b = 5, b + 5); is


a. Junk value
b. Syntax error
c. 5
d. 10

92. Minimum number of temporary variable needed to swap the contents of 2 variables is:
a. 1
b. 2
c. 3
d. 0
94. There is nothing like a virtual constructor of a class.
a. False
b. True

95. C++ provides facility to specify that the compiler should match function calls with the correct
definition at the run time. This process is called as
a. Static binding
b. Dynamic Binding

96. The output of this program is


int
main () { cout << "Hello World!" return 0; }

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
a. Hello World
b. Syntax error
c. 0
d. Hello World!

97. The return value of the following code is


Class1& test(Class1 obj)
{
Class1 *ptr = new Class1();
.........
return ptr;
}
a. object of Class1
b. reference to ptr
c. reference of Class1
d. object pointed by ptr

98. The output of


{
int a = 5;
int b = 10;
cout << (a>b?a:b);
}
a. 5
b. 10
c. Syntax error
d. None of above

99. The output of this program is


int a = 10;
void main()
{
int a = 20;
cout << a << ::a;
}
a. Syntax error
b. 10 20
c. 20 10
d. 20 20

100. Observe following program and answer


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

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)


C++ Questions & Answers JECRC UNIVERSITY JAIPUR
}
In the above example of constructor overloading, the following statement will call which constructor
Example obj = new Example (1,2,3);
a. Constructor 2
b. Constructor 4
c. Constrcutor 1
d. Type mismatch error

Answer Key
1-d 2-b 3-d 4-a 5-b 6-d 7-a 8-b 9-a 10 - d

11 - c 12 - d 13 - b 14 - d 15 - c 16 - a 17 - a 18 - b 19 - c 20 - c

21 - b 22 - a 23 - b 24 - c 25 - c 26 - d 27 - b 28 - b 29 - a 30 - c

31 - d 32 - c 33 - b 34 - a 35 - d 36 - c 37 - c 38 - a 39 - c 40 - a

41 - d 42 - d 43 - b 44 - d 45 - a 46 - a 47 - a 48 - c 49 - d 50 - d

51 - a 52 - b 53 - d 54 - a 55 - b 56 - c 57 - C 58 - D 59 - a 60 - a

61 - c 62 - c 63 - b 64 - c 65 - b 66 - b 67 - a 68 - d 69 - b 70 - d

71 - a 72 - a 73 - c 74 - c 75 - b 76 - c 77 - a 78 - c 79 - a 80 - c

81 - d 82 - d 83 - b 84 - d 85 - a 86 - b 87 - a 88 - b 89 - d 90 - a

91 - b 92 - d 93 - d 94 - a 95 - b 96 - b 97 - b 98 - b 99 - c 100 - b

Question Prepared By : Shekhar (IT Dept ,JECRC University Jaipur)

You might also like