EC2202/EC33 - Data structures and object oriented programming in CPP UNIT -1 -MCQS

 

EC2202/EC33 DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN CPP UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING

Introduction- Tokens-Expressions-contour Structures –Functions in C++, classes and objects, constructors and destructors ,operators overloading and type conversions

1.     C++ provides various types of …………………… tokens that include keywords, identifiers, constants, strings and operators.

 

A)  tokens

 

B)  expressions

 

C)  structures

 

D)  none

 

Ans: A

 

2.   …………………. refer to the names of variables, functions, arrays, classes etc. created by the programmer.

 

A)  Keywords

 

B)  Identifiers

 

C)  Constants

 

D)  Strings

 

Ans: B

 

3....................... are explicitly reserved identifiers and cannot be used as names for the program

variables or other user-defined program elements.

 

A)  Keywords

 

B)  Identifiers

 

C)  Constants

 

D)  Strings


Ans: A

 

4.  State whether the following statements are True or False for C++ identifiers.

 

i)  Only alphabetic characters, digits and underscores are permitted.

 

ii)  The name can start with a digit.

 

iii) Uppercase and lowercase letters are distinct.

 

A)  i-True, ii-True, iii-False

 

B)  i-True, ii-False, iii-True

 

C)  i-True, ii-False, iii-False

 

D)  i-True, ii-True, iii-True

 

Ans: B

 

5.    In C++, ………………….. refer to fixed values that do not change during the execution of a program.

 

A)  Identifiers

 

B)  Constants

 

C)  Strings

 

D)  Operators

 

Ans: B

 

6.  C++ provides an additional use of........................ , for declaration of generic pointers.

 

A)  int

 

B)  float

 

C)  void

 

D)  double

 

Ans: C


7.  The......................... data type was used to specify the return type of a function when it is not

returning any value.

 

A)  int

 

B)  float

 

C)  void

 

D)  double

 

Ans: C

 

8.   A ………………….. can be assigned a pointer value of any basic data type, but it may not de- referenced.

 

A)  int pointer

 

B)  void pointer

 

C)  generic pointer

 

D)  non-void pointer

 

Ans: C

 

9.  Which of the following is NOT the user-defined data type in C++.

 

A)  Structure

 

B)  Pointer

 

C)  Union

 

D)  Class

 

Ans: B

 

10.  Which of the following is/are the derived data types in C++.

 

i) array   ii) function    iii) pointer   iv) class

 

A)  i, ii and iii only

 

B)  ii, iii and iv only


C)  i, iii and iv only

 

D)  All i, ii, iii and iv

 

Ans: A

 

11.   In the case of ……………………… in C++, we can not modify the address that the pointer is initialized.

 

A)  constant pointer

 

B)  pointer to a constant

 

C)  pointer constant

 

D)  constant to a pointer

 

Ans: A

 

12.  In the case of........................... in C++, contents of what it points to cannot be changed.

 

A)  constant pointer

 

B)  pointer to a constant

 

C)  pointer constant

 

D)  constant to a pointer

 

Ans: B

 

13.  Which of the following is the correct way of declaring constant pointer in C++?

 

A)  char const * pointer1=”OK”;

 

B)  char * const pointer1=”OK”;

 

C)  const * char pointer1=”OK”;

 

D)  const char * pointer1=”OK”;

 

Ans: B

 

14.  Which of the following is the correct way of declaring a pointer to a constant in C++?


A)  int * const pointer1=&p;

 

B)  const * int pointer1=&p;

 

C)  int const * pointer1=&p;

 

D)  int pointer1 * const=&p;

 

Ans: C

 

15.    We can create …………………….. in C++ using the qualifier constant and defining a set of integer constant using enum keywords.

 

A)  basic constant

 

B)  number constant

 

C)  symbolic constant

 

D)  named constant

 

Ans: C

 

16.  The....................... are just like variables except that their values cannot be changed.

 

A)  basic constant

 

B)  number constant

 

C)  symbolic constant

 

D)  named constant

 

Ans: D

 

17..................... are widely used in C++ for memory management and to achieve polymorphism.

 

A)  Pointers

 

B)  Array

 

C)  Function

 

D)  Class                                                                                                                       Ans: A


18.   C++ permits initialization of the variables at run time which is referred to as ……………….

initialization.

 

A)  static

 

B)  dynamic

 

C)  variable

 

D)  runtime

 

Ans: B

 

19.   …………………….. used in C++ provides an alias (alternative name) for a previously defined variable.

 

A)  alias

 

B)  alternative

 

C)  defined

 

D)  reference

 

Ans: D

 

20.  A reference variable must be initialized at the time of ………………………………

 

A)  initialization

 

B)  declaration

 

C)  running

 

D)  definition

 

Ans: B

 

21.  Unary scope resolution operator is denoted by

 

A.  ! !

 

B.  % %

 

C.  :


D.  : :

 

Ans : D

 

Explanation: 1 is the minimum numbers of functions need to be presented in c++.

 

22.   Inline functions may not work               . i) If function contain static variables. ii) If function contain global and register variables. iii) If function returning value consists looping construct(i.e. for, while). iv) If inline functions are recursive. v) If function contains const value.

 

A.  Only i,iv & v

 

B.  Only ii,iii & v

 

C.  Only i,iii & iv

 

D.  All of the above

 

Ans : C

 

Explanation: int foo(int x, int y =5, int z=10) function declaration using default arguments is incorrect.

 

23.  How are many minimum numbers of functions need to be presented in c++?

 

A.  0

B.  1

C.  2

D.  3

Ans : B

 

Explanation: The main function is the mandatory part, it is needed for the execution of the program to start.

 

 

24.  Which of the following function declaration using default arguments is incorrect?

 

A.  int foo(int x, int y =5, int z=10)

B.  int foo(int x=5, int y =10, int z)

C.  int foo(int x=5, int y, int z=10)

D.  All are correct

Ans : A

 

Explanation: Default arguments in a function in C++ program is initialized from right to left.


25.  Which of the following statement is correct?

 

A.  Only one parameter of a function can be a default parameter.

B.  Minimum one parameter of a function must be a default parameter.

C.  All the parameters of a function can be default parameters.

D.  No parameter of a function can be default.

Ans : C

 

Explanation: All the parameters of a function can be default parameters statement is correct.

26.  Which of the following in Object Oriented Programming is supported by Function overloading and default arguments features of C++.

 

A.  Inheritance

B.  Polymorphism

C.  Encapsulation

D.  None of these

Ans : B

 

Explanation: Both of the features allow one function name to work for different parameter..

27.  What is the scope of the variable declared in the user defined function?

 

A.  Whole program

B.  Only inside the {} block

C.  The main function

D.  None of the above

Ans : B

 

Explanation: The variable is valid only in the function block as in other.

28.  Correct way to declare pure virtual function in a C++ class is

 

A.  Virtual void foo() =0 ;

B.  Void virtual foo()= { 0 }

C.  Virtual void foo() {} = 0;

D.  None of the above

Ans : A

 

Explanation: A is the correct declaration of pure virtual function in a class in C++.NOTE: Pure virtual function is used in an Interface or an abstract class

29.  Which of the following function / types of function cannot have default parameters?


A.  Member function of class

B.  Main()

C.  Member function of structure

D.  Both B and C

 

Ans : B

 

Explanation: None

30.  Which of the following is not correct for virtual function in C++ ?.

 

A.  Virtual function can be static.

B.  Virtual function should be accessed using pointers

C.  Virtual function is defined in base class

D.  Must be declared in public section of class

Ans : A

 

Explanation: Virtual function is can’t be static in C++.

31.  How many specifiers are present in access specifiers in class?

 

A.  2

B.  1

C.  4

D.  3

Ans : D

 

Explanation: There are three types of access specifiers. They are public, protected and private.

32.  Which of these following members are not accessed by using direct member access operator?

 

A.  Public

B.  Private

C.  Protected

D.  Both B & C

Ans : D

 

Explanation: Because of the access is given to the private and protected, We can’t access them by using direct member access operator.

33.  Which other keywords are also used to declare the class other than class?

 

A.  Struct

B.  Union


C.  Object

D.  Both struct & union                                 Ans : D

 

Explanation: Struct and union take the same definition of class but differs in the access techniques.

34.  Which of the following is true?

 

A.  All objects of a class share all data members of class

B.  Objects of a class do not share non-static members. Every object has its own copy

C.  Objects of a class do not share codes of non-static methods, they have their own copy

D.  None of these

Ans : B

 

Explanation: very object maintains a copy of non-static data members. For example, let Student be a class with data members as name, year, batch. Every object of student will have its own name, year and batch. On a side note, static data members are shared among objects. All objects share codes of all methods

35.  Which of the following can be overloaded?

 

A.  Object

B.  Operators

C.  Both A & B

D.  None of the above

Ans : C

 

Explanation: Object and Operators can be overloaded.

36.  Which is also called as abstract class?

 

A.  Virtual function

B.  Derived class

C.  Pure virtual function

D.  None of the mentioned

Ans : C

 

Explanation: Classes that contain at least one pure virtual function are called as abstract base classes.

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

 

#include <iostream> using namespace std;


class LFC

 

{

 

static int x; public:

static void Set(int xx)

 

{

 

x = xx;

 

}

 

void Display()

 

{

 

cout<< x ;

 

}

 

};

 

int LFC::x = 0; int main()

{

 

LFC::Set(33);

 

LFC::Display(); return 0;

}

 

A.  The program will print the output 0.

B.  The program will print the output 33.

C.  The program will print the output Garbage.

D.  The program will report compile time error.

 

Ans : D


Explanation: The program will report compile time error: cannot call member function "void LFC::Display()" without object

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

Note:Includes all required header files class course

{

 

int x, y; public: course(int xx)

{

 

x = ++xx;

 

}

 

void Display()

 

{

 

cout<< --x << " ";

 

}

 

};

 

int main()

 

{

 

course obj(20); obj.Display();

int *p = (int*)&obj ;

 

*p = 5; obj.Display(); return 0;


}

 

A. 20 4

B. 21 4

C. 20 5

D. 21 5

 

Ans : A

 

Explanation: 20 4 will be the output of the following program

39.  What is the output of this program? Note:Includes all required header files

 

using namespace std; class Empty {};

int main()

 

{

 

cout << sizeof(Empty); return 0;

}

 

A.  A non-zero value.

B.  0

C.  Compiler Error

D.  Runtime Error

 

Ans : A

 

Explanation: Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses

40.  What will be the output of this program?

Note:Includes all required header files using namespace std;

class sample

 

{


int x;

 

}

 

int main()

 

{

 

sample obj; obj.x=100; cout<<"x="<< obj.x;

}

 

A.  10

B. 100

C. Error

D. None of the above

Ans : C

 

Explanation: By default, class data members and member functions are private, and we cannot access private members outside of the class.

41.  What will be the output of this program?

Note:Includes all required header files using namespace std;

//Empty class class test

{

 

};

 

 

int main()

 

{

 

test testObj;

 

cout<<"size ="<< sizeof(testObj);


return 0;

 

}

 

A.  Error

B.  size =Garbage

C.  size =1

D.  Compile but no output

 

Ans : C

 

Explanation: size =1 An empty class object takes 1 byte in the memory, but it is not fixed it can be take any non zero value depending on the compiler and class definition.

42.  What does the cerr represent?

 

A.  Standard error stream

B.  Standard logging stream

C.  Input stream

D.  Output stream

 

Ans : A

 

Explanation: cerr is an object of class ostream that represents the standard error stream. It is associated with the cstdio stream stderr

43.  What will be the output of the following program? #include <iostream>

 

using namespace std; class LFC {

LFC() { cout << "Constructor called"; }

 

};

 

 

int main()

 

{

 

LFC t1;

 

return 0;


}

 

A.  Compiler Error

B.  Runtime Error

C.  Constructor called

D.  destructor for id 1

 

Ans : A

 

Explanation: By default all members of a class are private. Since no access specifier is there for find(), it becomes private and it is called outside the class when t1 is constructed in main.

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

 

 

#include <iostream> using namespace std; class LFC

{

 

int id;

 

static int count; public:

LFC() {

 

count++; id = count;

cout << "constructor for id " << id << endl;

 

}

 

~LFC() {

 

cout << "destructor for id " << id << endl;

 

}

 

};


int LFC::count = 0; int main() {

LFC a[3];

 

return 0;

 

}

 

A.  constructor for id 1 constructor for id 2 constructor for id 3 destructor for id 3 destructor for id 2 destructor for id 1

B.  constructor for id 1 constructor for id 2 constructor for id 3 destructor for id 1 destructor for id 2 destructor for id 3

C.  Compiler Dependent

D.  constructor for id 1 destructor for id 1

 

Ans : D

 

Explanation: In the above program, id is a static variable and it is incremented with every object creation. Object a[0] is created first, but the object a[2] is destroyed first. Objects are always destroyed in reverse order of their creation. The reason for reverse order is, an object created later may use the previously created object.

45.  Which contructor function is designed to copy object of same class type?

 

A.  Copy constructor

B.  Create constructor

C.  Object constructor

D.  Dynamic constructor

 

Ans : A

 

Explanation: Copy constructor function is designed to copy object of same class type.

46.  Destructors                      for automatic objects if the program terminates with a call to function exit or function abort

 

A.  Are called

B.  Are not called

C.  Are inherited

D.  Are created


Ans : B

 

Explanation: Destructors Are not called for automatic objects if the program terminates with a call to function exit or function abort

47.  Which of the following is true about constructors. i) They cannot be virtual ii) They cannot be private. iii) They are automatically called by new operator.

 

A.  All i,ii,iii

B.  i & iii

C.  ii & iii

D.  i & ii

 

Ans : B

 

Explanation: i) True: Virtual constructors don't make sense, it is meaningless to the C++ compiler to create an object polymorphically. ii) False: Constructors can be private

48.  State whether the following statements about the constructor are True or False. i) constructors should be declared in the private section. ii) constructors are invoked automatically when the objects are created.

 

A.  True,True

B.  True,False

C.  False,True

D.  False,False

Ans : C

 

Explanation: Statement 1 is false and statement 2 is true.

49.  Like constructors, can there be more than one destructors in a class?

 

A.  Yes

B.  No

C.  May Be

D.  Can't Say

 

Ans : B

 

Explanation: There can be only one destructor in a class. Destructor's signature is always

~ClassNam()and they can not be passed arguments.

50.  Destructor has a same name as the constructor and it is preceded by?


A.  !

B.  ?

C.  ~

D.  $

 

Ans : C

 

Explanation: Destructor has a same name as the constructor and it is preceded by ~.

51.  Which of the following gets called when an object is being created?

 

A.  Constuctor

B.  Virtual Function

C.  Destructors

D.  Main

 

Ans : A

 

Explanation: Virtual Function gets called when an object is being created.

 

 

52.  Which of the followings is/are automatically added to every class, if we do not write our own.

 

A.  Copy Constructor.

B.  Assignment Operator

C.  A constructor without any parameter

D.  All of the above

 

Ans : D

 

Explanation: In C++, if we do not write our own, then compiler automatically creates a default constructor, a copy constructor and a assignment operator for every class..

53.  Which is the correct statement anout operator overloading in C++?.

 

A.  Only arithmetic operators can be overloaded

B.  Associativity and precedence of operators does not change

C.  Precedence of operators are changed after overlaoding

D.  Only non-arithmetic operators can be overloaded

 

Ans : B


Explanation: Both arithmetic and non-arithmetic operators can be overloaded. Priority and affiliation of operators remain before and after operator overloading.

 

 

54.  Which of the following operators cannot be overloaded?

 

A.  .* (Pointer-to-member Operator )

B.  :: (Scope Resolution Operator)

C.  .* (Pointer-to-member Operator )

D.  All of the abover

Ans : D

 

Explanation: All of the above operator cannot be overloaded.

 

 

55.  While overloading binary operators using member function, it requires       argument?

 

A.  2

B.  1

C.  0

D.  3

 

Ans : B

 

Explanation: While overloading binary operators using member function, it requires 0 argument.

 

 

56.  Which of the following operators should be preferred to overload as a global function rather than a member method?

 

A.  Postfix ++

B.  Comparison Operator

C.  Insertion Operator <<

D.  prefix ++

 

Ans : C

 

Explanation: Insertion Operator should be preferred to overload as a global function rather than a member method.


 

 

57.  Which of the following operator functions cannot be global, i.e., must be a member function.

 

A.  new

B.  delete

C.  Converstion Operator

D.  All of the above                                                               Ans : C

 

Explanation: Converstion Operator functions cannot be global, i.e., must be a member function.

 

 

58.  Which of the following is correct option?

 

A. x = 5, y = 10

B. x = 10, y = 5

C. Compile Error

D. x = 5, y = 5

 

Ans : A

 

Explanation: This function call is a simple example of operator overloading. The function call operator, when overloaded, does not modify how the function is called. Rather, it modifies how to interpret the operator when applied to objects of a given type.

 

 

59.  Which of the following is correct option?

 

A. x = 15, y = 3

B. x = 3, y = 15

C. Compile Error

D. x = 15, y = 15

 

Ans : B

 

Explanation: This function call is a simple example of operator overloading. The function call operator, when overloaded, does not modify how the function is called. Rather, it modifies how to interpret the operator when applied to objects of a given type.


60.  Which of the following is correct option?

 

A.  lets(int) called

B.  lets(lfc 2) called

C.  Compiler Error: Ambiguous call to lets()

D.  No error and No output

 

Ans : C

 

Explanation: The class lfc has two conversion operators overloaded, int and lfc1. And there are two lets() for int and lfc1.

 

 

61.  Which of the following is the correct order involves in the process of operator overloading.

i)  Define the operator function to implement the required operations. ii) Create a class that defines the data type that is to be used in the overloading operation. iii) Declare the operator function op() in the public part of the class.

 

A.  1-i, 2-ii, 3-iii

B.  1-ii, 2-iii, 3-i

C.  1-ii, 2-i, 2-iii

D.  1-iii, 2-ii, 3-i

 

Ans : B

 

Explanation: 1-ii, 2-iii, 3-i is the correct order involves in the process of operator overloading.

 

 

62.  Which of the following is correct option?

 

A.  Compiler Error

B. 8 10

C. 8 8

D. 10 8

 

Ans : B

 

Explanation: Note that the class LFC1 has as conversion operator overloaded, so an object of LFC1 can be converted to that of LFC. Also, class LFC has a constructor which can be called with single integer argument, so an int can be converted to LFC.


Comments

Popular posts from this blog

Anna University Exam Dec 2024 time table

ANNA UNIVERSITY SPECIAL ARREAR TIMETABLE MAY/JUNE 2025