0% found this document useful (0 votes)
149 views146 pages

Oop Mcqs Unit III

The document contains 23 multiple choice questions related to pointers and functions in C++. Each question has a unique ID number, the question text, possible answer choices A-D, and the correct answer. The questions cover topics such as pointer declaration and dereferencing, function pointers, passing pointers to functions, and using pointers with classes.

Uploaded by

Prasad Mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views146 pages

Oop Mcqs Unit III

The document contains 23 multiple choice questions related to pointers and functions in C++. Each question has a unique ID number, the question text, possible answer choices A-D, and the correct answer. The questions cover topics such as pointer declaration and dereferencing, function pointers, passing pointers to functions, and using pointers with classes.

Uploaded by

Prasad Mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 146

Id 1

Question What does the following statement mean?


int (*fp)(char*)
A pointer to a pointer
B pointer to an array of chars
C pointer to function taking a char* argument and returns an int
D function taking a char* argument and returning a pointer to int
Answer C
Marks 1
Unit III

Id 2
Question The operator used for dereferencing or indirection is ____
A *
B &
C ->
D –>>
Answer A
Marks 1
Unit III
Id 3
Question Choose the right option
string* x, y;
A x is a pointer to a string, y is a string
B y is a pointer to a string, x is a string
C both x and y are pointer to string types
D none of the mentioned
Answer A
Marks 1
Unit III
Id 4
Question Which one of the following is not a possible state for a pointer?
A hold the address of the specific object
B point one past the end of an object
C Zero
D point to a byte
Answer D
Marks 1
Unit III
Id 5
Question Which of the following is illegal?
A int *ip;
B string s, *sp = 0;
C int i; double* dp = &i;
D int *pi = 0;
Answer D
Marks 1
Unit III
Id 6
Question #include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout <<arr[1];
return 0;
}

A 10
B 15
C 20
D Random number
Answer D
Marks 2
Unit III
Id 7
Question The correct statement for a function that takes pointer to a float, a pointer to a pointer to a
char and returns a pointer to a pointer to a integer is
A int **fun(float**, char**)
B int *fun(float*, char*)
C int ***fun(float*, char**)
D int ***fun(*float, **char)
Answer C
Marks 1
Unit III
Id 8
Question #include <iostream>
using namespace std;
int main()
{
char arr[20];
int i;
for(i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
cout << arr;
return(0);
}

A ABCDEFGHIJ
B AAAAAAAAA
C JJJJJJJJJJJJ
D None
Answer A
Marks 2
Unit III

Id 9
Question #include <iostream>
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}

A fg
B cdef
C defg
D abcd
Answer A
Marks 2
Unit III

Id 10
Question Which rule will not affect the friend function?
A private and protected members of a class cannot be accessed from outside
B private and protected member can be accessed anywhere
C both a &b
D None
Answer A
Marks 1
Unit III

Id 11
Question Which keyword is used to declare the friend function?
A Firend
B friend
C Classfriend
D myfriend
Answer B
Marks 1
Unit III

12
Question #include <iostream>
using namespace std;
class Box
{
double width;
public:
friend void printWidth( Box box );
void setWidth( double wid );
};
void Box::setWidth( double wid )
{
width = wid;
}
void printWidth( Box box )
{
box.width = box.width * 2;
cout << "Width of box : " << box.width << endl;
}
int main( )
{
Box box;
box.setWidth(10.0);
printWidth( box );
return 0;
}

A 40
B 5
C 10
D 20
Answer D
Marks 2
Unit III

Id 13
Question Pick out the correct statement.
A A friend function may be a member of another class.
B A friend function may not be a member of another class.
C A friend function may or may not be a member of another class.
D None of the mentioned
Answer C
Marks 1
Unit III
Id 14
Question Where does keyword „friend‟ should be placed?
A function declaration
B function definition
C main function
D None
Answer A
Marks 1
Unit
Id 15
Question #include <iostream>
using namespace std;
class sample
{
private:
int a, b;
public:
void test()
{
a = 100;
b = 200;
}
friend int compute(sample e1);
};
int compute(sample e1)
{
return int(e1.a + e1.b) - 5;
}
int main()
{
sample e;
e.test();
cout << compute(e);
return 0;
}

A 100
B 200
C 300
D 295
Answer D
Marks 2
Unit
Id 16
Question #include <iostream>
using namespace std;
class base
{
int val1, val2;
public:
int get()
{
val1 = 100;
val2 = 300;
}
friend float mean(base ob);
};
float mean(base ob)
{
return float(ob.val1 + ob.val2) / 2;
}
int main()
{
base obj;
obj.get();
cout << mean(obj);
return 0;
}
A 200
B 150
C 100
D 300
Answer
Marks 2
Unit

Id 17
Question To which does the function pointer point to?
A Variable
B Constants
C Function
D absolute variables
Answer C
Marks 1
Unit
Id 18
Question What we will not do with function pointers?
A allocation of memory
B de-allocation of memory
C both a &b
D None
Answer C
Marks 1
Unit
Id 19
Question #include <iostream>
using namespace std;
int add(int first, int second)
{
return first + second + 15;
}
int operation(int first, int second, int (*functocall)(int, int))
{
return (*functocall)(first, second);
}
int main()
{
int a;
int (*plus)(int, int) = add;
a = operation(15, 10, plus);
cout << a;
return 0;
}

A 25
B 36
C 40
D 45
Answer C
Marks 2
Unit

Id 20
Question #include <iostream>
using namespace std;
void func(int x)
{
cout << x ;
}
int main()
{
void (*n)(int);
n = &func;
(*n)( 2 );
n( 2 );
return 0;
}

A 2
B 21
C 22
D 20
Answer C
Marks 2
Unit
21
Question #include <iostream>
using namespace std;
int n(char, int);
int (*p) (char, int) = n;
int main()
{
(*p)('d', 9);
p(10, 9);
return 0;
}
int n(char c, int i)
{
cout << c << i;
return 0;
}

A d9
9
B d9d9
C d9
D Compile time error
Answer A
Marks 2
Unit
Id 22
Question #include <iostream>
using namespace std;
int func (int a, int b)
{
cout << a;
cout << b;
return 0;
}
int main(void)
{
int(*ptr)(char, int);
ptr = func;
func(2, 3);
ptr(2, 3);
return 0;
}

A 2323
B 232
C 23
D Compile time error
Answer D
Marks 2
Unit
Id 23
Question What are the mandatory part to present in function pointers?
A &
B return values
C Data types
D None
Answer C
Marks 1
Unit
Id 24
Question 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
Marks 1
Unit
Id 25
Question What is size of generic pointer in c?
A 0
B 1
C 2
D Null
Answer C
Marks 1
Unit
Id 26
Question Void pointer can point to which type of objects?
A Int
B Float
C Double
D All
Answer D
Marks 1
Unit
Id 27
Question What does the following statement mean?
int (*fp)(char*)
A pointer to a pointer
B pointer to an array of chars
C pointer to function taking a char* argument and returns an int
D function taking a char* argument and returning a pointer to int
Answer C
Marks 1
Unit
Id 28
Question What is size of generic pointer in C++ (in 32-bit platform) ?
A 2
B 4
C 8
D 0
Answer B
Marks 1
Unit
Id 29
Question #include <iostream>
using namespace std;
int main()
{
int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
return 0;
}

A 15 18 21
B 21 21 21
C 24 24 24
D Compile time error
Answer B
Marks 2
Unit
Id 30
Question #include <iostream>
using namespace std;
int main()
{
int i;
char *arr[] = {"C", "C++", "Java", "VBA"};
char *(*ptr)[4] = &arr;
cout << ++(*ptr)[2];
return 0;
}
A ava
B java
C c++
D Compile time error
Answer A
Marks 2
Unit
Id 31
Question #include <iostream>
using namespace std;
int main()
{
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *p;
return 0;
}

A 4
B 5
C 6
D 7
Answer B
Marks 2
Unit
Id 32
Question #include <iostream>
using namespace std;
int main()
{
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << arr;
return 0;
}
A 4
B 5
C Address of arr
D 7
Answer C
Marks 2
Unit
Id 33
Question #include <iostream>
using namespace std;
int main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p + 4) = 50;
for (int n = 0; n < 5; n++)
cout << numbers[n] << ",";
return 0;
}

A 10,20,30,40,50,
B 1020304050
C Compile time error
D Runtime error
Answer A
Marks 2
Unit
Id 34
Question #include <iostream>
using namespace std;
int main()
{
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *arr + 9;
return 0;
}

A 12
B 5
C 13
D Error
Answer C
Marks 2
Unit
Id 35
Question A void pointer cannot point to which of these?
A methods in c++
B class member in c++
C all of the mentioned
D None
Answer D
Marks 1
Unit
Id 36
Question #include <iostream>
using namespace std;
int func(void *Ptr);
int main()
{
char *Str = "abcdefghij";
func(Str);
return 0;
}
int func(void *Ptr)
{
cout << Ptr;
return 0;
}

A abcdefghij
B address of string “abcdefghij”
C Compile time
D Run time error
Answer B
Marks 2
Unit
Id 37
Question #include <iostream>
using namespace std;
int main()
{
int *p;
void *vp;
if (vp == p);
cout << "equal";
return 0;
}
A Equal
B No output
C Compile time error
D Run time error
Answer A
Marks 2
Unit III
Id 38
Question #include <iostream>
using namespace std;
int main()
{
int n = 5;
void *p = &n;
int *pi = static_cast<int*>(p);
cout << *pi << endl;
return 0;
}
A 5
B 6
C Compile time error
D Run time error
Answer A
Marks 2
Unit
Id 39
Question #include <iostream>
using namespace std;
int main()
{
int a = 5, c;
void *p = &a;
double b = 3.14;
p = &b;
c = a + b;
cout << c << '\n' << p;
return 0;
}

A 8, memory address
B 8.14
C memory address
D None
Answer A
Marks 2
Unit

Id 40
Question What we can‟t do on a void pointer?
A pointer arithemetic
B pointer functions
C Both
D None
Answer A
Marks 2
Unit

Id 41
Question Which value we cannot assign to reference?
A Integer
B Floating
C Unsigned
D Null
Answer D
Marks 1
Unit

Id 42
Question #include <iostream>
using namespace std;
int main()
{
int a = 9;
int & aref = a;
a++;
cout << "The value of a is " << aref;
return 0;
}

A 9
B 10
C 11
D Error
Answer B
Marks 2
Unit
Id 43
Question #include <iostream>
using namespace std;
void print (char * a)
{
cout << a << endl;
}
int main ()
{
const char * a = "Hello world";
print(const_cast<char *> (a) );
return 0;
}

A Hello world
B Hello
C World
D Compile time error
Answer A
Marks 2
Unit

Id 44
Question Identify the correct sentence regarding inequality between reference and pointer.
A we can not create the array of reference.
B we can create the Array of reference.
C we can use reference to reference.
D None
Answer A
Marks 1
Unit

Id 45
Question Which is used to tell the computer that where a pointer is pointing to?
A Dereference
B Reference
C heap operations
D None
Answer A
Marks 1
Unit

Id 46
Question #include <iostream>
using namespace std;
int main()
{
int x;
int *p;
x = 5;
p = &x;
cout << *p;
return 0;
}

A 5
B 10
C Memory address
D None
Answer A
Marks 2
Unit

Id 47
Question #include <iostream>
using namespace std;
int main()
{
int x = 9;
int* p = &x;
cout << sizeof(p);
return 0;
}

A 4
B 2
C Depends on compiler
D None
Answer C
Marks 2
Unit

Id 48
Question #include <iostream>
using namespace std;
int main()
{
double arr[] = {5.0, 6.0, 7.0, 8.0};
double *p = (arr+2);
cout << *p << endl;
cout << arr << endl;
cout << *(arr+3) << endl;
cout << *(arr) << endl;
cout << *arr+9 << endl;
return 0;
}

A 7
0xbf99fc98
8
5
14
B 7
8
0xbf99fc98
5
14
C 0xbf99fc98
D None
Answer A
Marks 2
Unit

Id 49
Question What does the dereference operator will return?
A rvalue equivalent to the value at the pointer address.
B lvalue equivalent to the value at the pointer address.
C it will return nothing
D None
Answer B
Marks 2
Unit

Id 50
Question Which operator is used in pointer to member function?
A .*
B ->*
C Both a &b
D None
Answer C
Marks 2
Unit

Id 51
Question #include <iostream>
using namespace std;
class Foo
{
public:
Foo(int i = 0){ _i = i;}
void f()
{
cout << "Executed"<<endl;
}
private:
int _i;
};
int main()
{
Foo *p = 0;
p -> f();
}

A Executed
B Error
C Run time error
D None
Answer A
Marks 2
Unit

Id 52
Question Which is the best design choice for using pointer to member function?
A Interface
B Class
C Structure
D None
Answer A
Marks 2
Unit
Id 53
Question Virtual functions allow you to
A create an array of type pointer-to-base class that can hold pointers to derived classes.
B create functions that can never be accessed.
C group objects of different classes so they can all be accessed by the same function code.
D use the same function call to execute member functions of objects from different classes.
Answer D
Marks 1
Unit III
Id 54
Question A pointer to a base class can point to objects of a derived class.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit III
Id 55
Question A pure virtual function is a virtual function that
A causes its class to be abstract.
B returns nothing.
C is used in a base class.
D A and C
Answer D
Marks 1
Unit III
Id 56
Question An abstract class is useful when
A no classes should be derived from it.
B there are multiple paths from one derived class to another.
C no objects should be instantiated from it.
D you want to defer the declaration of the class.
Answer C
Marks 1
Unit III
Id 57
Question A friendfunction can access a class‟s private data without being a member of the class.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit III
Id 58
Question A friend function can be used to
A mediate arguments between classes.
B increase the versatility of an overloaded operator.
C allow access to an unrelated class.
D B and C
Answer D
Marks 1
Unit III
Id 59
Question The keyword friend appears in
A the class allowing access to another class.
B the private section of a class.
C the public section of a class.
D All of the above
Answer D
Marks 1
Unit III
Id 60
Question A static function
A should be called when an object is destroyed.
B is closely connected to an individual object of a class.
C can be called using the class name and function name.
D is used when a dummy object must be created.
Answer C
Marks 1
Unit III
Id 61
Question An assignment operator might be overloaded to
A help keep track of the number of identical objects.
B assign a separate ID number to each object.
C signal when assignment takes place.
D All of the above
Answer D
Marks 1
Unit III
Id 62
Question The user must always define the operation of the copy constructor.
A TRUE
B FALSE
C
D
Answer B
Marks 1
Unit III
Id 63
Question The operation of the assignment operator and that of the copy constructor are
A similar, except that the copy constructor creates a new object.
B different, except that they both copy member data.
C different, except that they both create a new object.
D A and B
Answer D
Marks 1
Unit III
Id 64
Question A copy constructor could be defined to copy only part of an object‟s data.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit III
Id 65
Question The lifetime of a variable that is
A local to a member function coincides with the lifetime of the function.
B global coincides with the lifetime of a class.
C nonstatic member data of an object coincides with the lifetime of the object.
D A and C
Answer D
Marks 1
Unit III
Id 66
Question There is no problem with returning the value of a variable defined as local within a
member function so long as it is returned by value.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit III
Id 67
Question A copy constructor is invoked when
A a function returns by value.
B an argument is passed by value.
C A and B
D an argument is passed by reference.
Answer C
Marks 2
Unit III
Id 68
Question What does the thispointer point to?
A Data member of the class
B the object of which the function using it is a member
C Member function
D Base class
Answer B
Marks 1
Unit III
Id 69
Question A pointer is
A the address of a variable.
B an indication of the variable to be accessed next.
C a variable for storing addresses.
D the data type of an address variable.
Answer C
Marks 1
Unit III
Id 70
Question The expression *testcan be said to
A refer to the contents of test.
B dereference test.
C refer to the value of the variable pointed to by test.
D All of the above
Answer D
Marks 2
Unit III
Id 71
Question A pointer to void can hold pointers to __________
A int
B float
C char
D Any data type
Answer D
Marks 1
Unit III
Id 72
Question The type of variable a pointer points to must be part of the pointer‟s definition so that
A data types don‟t get mixed up when arithmetic is performed on them.
B pointers can be added to one another to access structure members.
C the compiler can perform arithmetic correctly to access array elements.
D A and C
Answer D
Marks 2
Unit III
Id 73
Question The first element in a string is
A the name of the string.
B the first character in the string.
C the length of the string.
D the name of the array holding the string.
Answer b
Marks 1
Unit III
Id 74
Question The newoperator
A returns a pointer to a variable.
B creates a variable called new.
C obtains memory for a new variable.
D A and C
Answer D
Marks 2
Unit III
Id 75
Question Definition for an array arrof 8 pointers that point to variables of type floatis
A *float arr[8]
B float* arr[8];
C float pointer[8]
D int *ary[8]
Answer B
Marks 1
Unit III
Id 76
Question The delete operator returns ____________ to the operating system.
A Memory that is no longer needed
B Pointer
C Object
D Class
Answer A
Marks 1
Unit III
Id 77
Question In a linked list
A each link contains a pointer to the next link.
B each link contains data or a pointer to data.
C the links are stored in an array.
D A and B
Answer D
Marks 2
Unit III
Id 78
Question If you wanted to sort many large objects or structures, it would be most efficient to
A place them in an array and sort the array.
B place pointers to them in an array and sort the array.
C place them in a linked list and sort the linked list.
D place references to them in an array and sort the array.
Answer B
Marks 1
Unit III
Id 79
Question The contents of two pointers that point to adjacent variables of type floatdiffer by _____
A 1 byte
B 2 bytes
C 3 bytes
D 4 bytes
Answer D
Marks 1
Unit III
Id 80
Question Which of the following is true about virtual functions in C++.
A Virtual functions are functions that can be overridden in derived class with the same
signature.
B Virtual functions enable run-time polymorphism in a inheritance hierarchy.
C If a function is 'virtual'in the base class, the most-derived class's implementation of the
function is called according to the actual type of the object referred to, regardless of the
declared type of the pointer or reference. In non-virtual functions, the functions are called
according to the type of reference or pointer
D All of the above
Answer D
Marks 1
Unit III
Id 81
Question Predict the output of following C++ program.

#include<iostream>
using namespace std;
class Base {
public:
Base() { cout<<"Constructor: Base"<<endl; }
virtual ~Base() { cout<<"Destructor : Base"<<endl; }
};
class Derived: public Base {
public:
Derived() { cout<<"Constructor: Derived"<<endl; }
~Derived() { cout<<"Destructor : Derived"<<endl; }
};
int main() {
Base *Var = new Derived();
delete Var;
return 0;
}
A Constructor: Base
Constructor: Derived
Destructor : Derived
Destructor : Base
B Constructor: Base
Constructor: Derived
Destructor : Base
C Constructor: Base
Constructor: Derived
Destructor : Derived
D Constructor: Derived
Destructor : Derived
Answer A
Marks 2
Unit III
Id 82
Question Predict the output of following C++ program. Assume that there is no alignment and a
typical implementation of virtual functions is done by the compiler.

#include <iostream>
using namespace std;

class A
{
public:
virtual void fun();
};

class B
{
public:
void fun();
};

int main()
{
int a = sizeof(A), b = sizeof(B);
if (a == b) cout <<"a == b";
else if (a >b) cout <<"a >b";
else cout <<"a <b";
return 0;
}
A a>b
B a==b
C a<b
D Compiler error
Answer A
Marks 2
Unit III
Id 83
Question Which of the following is FALSE about references in C++
A A reference must be initialized when declared
B Once a reference is created, it cannot be later made to reference another object; it cannot
be reset
C References cannot be NULL
D References cannot refer to constant value
Answer D
Marks 1
Unit III
Id 84
Question #include <iostream>
using namespace std;

class A
{
public:
virtual void fun() { cout <<"A::fun() "; }
};

class B: public A
{
public:
void fun() { cout <<"B::fun() "; }
};

class C: public B
{
public:
void fun() { cout <<"C::fun() "; }
};

int main()
{
B *bp = new C;
bp->fun();
return 0;
}

Which function will be called by statements bp->fun();?


A A::fun()
B B::fun()
C C::fun()
D Compiler error
Answer C
Marks 2
Unit III
Id 85
Question 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
Answer D
Marks 2
Unit II
Id 85
Question What is the output of following program?
#include<iostream>
using namespace std;
class Point {
Point() { cout <<"Constructor called"; }
};

int main()
{
Point t1;
return 0;
}
A Compiler Error
B Runtime Error
C Constructor called
D Segmentation Fault
Answer A
Marks 1
Unit III
Id 86
Question What will be the output of following program?

#include <iostream>
using namespace std;

class Test
{
public:
Test() { cout <<"Hello from Test() "; }
} a;

int main()
{
cout <<"Main Started ";
return 0;
}
A Main Started
B Main Started Hello from Test()
C Hello from Test() Main Started
D Compiler Error: Global objects are not allowed
Answer C
Marks 2
Unit II
Id 87
Question Which rule will not affect the friend function
A private &protected members of a class cannot be accessed from outside
B private &protected member can be accessed anywhere
C both a &b
D none of these
Answer A
Marks 1
Unit III
Id 88
Question which keyword is used to declare the friend function
A Friend
B Class Friend
C My friend
D all above
Answer A
Marks 1
Unit III

Id 89
Question what is syntax of friend function?
A Friend class1 Class2;
B Friend class;
C Friend class
D none of these
Answer D
Marks 1
Unit III

Id 90
Question what is output of the program?
#include<iostream>
using namespace std;
class Box
{
double width;
public:
friend void printWidth(Box box);
void setWidth(double wid);
};
void Box::setWidth(double wid)
{
width-=wid;
}
void printWidth(Box box)
{
box.width=box.width*2;
cout<<"Width of box :"<<box.width<<endl;
}
int main()
{
Box box;
box.setWidth(10.0);
printWidth(box);
return 0;
}
A 40
B 5
C 10
D 20
Answer D
Marks 1
Unit III

Id 91
Question pick out the correct statement.
A A friend function may be member of another class
B A friend function may not be member of another class
C A friend function may or may not be member of another class
D none of these
Answer C
Marks 1
Unit III

Id 92
Question Where does keyword 'friend' should be placed?
A Function declaration
B Function definition
C Main function
D none of these
Answer A
Marks 1
Unit III

Id 94
Question 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 C
Marks 1
Unit 3
Id 95
Question Which of the following is not type of constructor?
A Copy constructor
B Friend constructor
C Default constructor
D Parameterized constructor
Answer B
Marks 1
Unit III
Id 96
Question Which of the following statement 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 B
Marks 1
Unit III
Id 97
Question Which of the following is not the member of class?
A Static function
B Friend function
C Const function
D Virtual function
Answer B
Marks 1
Unit III
Id 98
Question Which of the following is not member of class?
A Data hiding
B Dynamic Typing
C Dynamic binding
D Dynamic loading
Answer C
Marks 1
Unit III
Id 99
Question The operator used for dereferencing or indirection is______________
A *
B &
C ->
D ->>
Answer D
Marks 1
Unit III
Id 100
Question Choose the right option
string* x, y
A x is pointer to string, y is a string
B y is pointer to string , x is a string
C both x &y are pointer to string types
D none of these
Answer A
Marks 1
Unit III
Id 101
Question Which one of the following is not a possible state for a pointer?
A hold the address of specific object
B point one past the end of an object
C Zero
D point to tye
Answer D
Marks 1
Unit 3
Id 102
Question Which of the following is illegal?
A int *ip;
B string s, *sp=0;
C int i;double *dp=&i;
D int *pi=0;
Answer C
Marks 1
Unit 3
Id 103
Question what will happen in the code?
int a=100,b=200;
int *p=&a, *q=&b;
p=q;
A b is assigned to a
B p now points to b
C a is assigned to b
D q now points to a
Answer B
Marks 1
Unit III
Id 104
Question what is output of this program?
#include<iostream>
using namespace std;
int main()
{
int a=5, b=10, c=15;
int *arr[]= {&a, &b, &c};
cout<<arr[1];
return 0;
}
A 5
B 10
C 15
D it will return some random number
Answer D
Marks 1
Unit III
Id 105
Question The correct statement for a function that takes pointer to a float , a pointer to a ponter to a
char &return a pointer to a integer is
A int**fun(float**, char**)
B int *fun(float*, char*)
C int ***fun(float*, char**)
D int ***fun(*float, **char)
Answer C
Marks 1
Unit III
Id 106
Question What is size of generic pointer in C++(in 32-bit platform)?
A 2
B 4
C 8
D 0
Answer B
Marks 1
Unit 3
Id 107
Question What is the output of this program?
#include<iostream>
using namespace std;
int main()
{
int a[2][4]={3,6,9,12,15,18,21,24};
cout<<*(a[1] + 2)<<*(*(a+1)+2)<<2[1[a]];
return 0;
}
A 15 18 21
B 21 21 21
C 24 24 24
D compile time error
Answer B
Marks 1
Unit 3
Id 108
Question Void pointer can point to which type of objects?
A Int
B Float
C Double
D all of above
Answer D
Marks 1
Unit 3
Id 109
Question When does the void pointer can be dereferenced?
A when it doesn't point to any value
B when it cast to another type of object
C using delete keyword
D none of above
Answer B
Marks 1
Unit 3
Id 110
Question The pointer can point to any variable that is not declared with which of these?
A Const
B Volatile
C both a &b
D Static
Answer C
Marks 1
Unit 3
Id 111
Question A void pointer can not point to which of these?
A methods in C++
B class member in c++
C both a &b
D none of these
Answer B
Marks 1
Unit 3
Id 112
Question what we can‟t do on void pointer?
A pointer arithmetic
B pointer functions
C both a &b
D none of these
Answer A
Marks 1
Unit 3
Id 113
Question To which does the function pointer point to?
A Variable
B Constants
C Function
D absolute variables
Answer C
Marks 1
Unit 3
Id 114
Question What we will not do with function pointers?
A Allocation of memory
B De-allocation of memory
C both a &b
D none of these
Answer C
Marks 1
Unit 3
Id 115
Question Which of the following can be passed in function pointers?
A Variables
B data types
C Functions
D none of these
Answer C
Marks 1
Unit 3
Id 116
Question Which operators are used in free store?
A New
B Delete
C both a &b
D none of these
Answer C
Marks 1
Unit 3
Id 117
Question What type of class member is operator new?
A Static
B Dynamic
C Const
D Smart
Answer A
Marks 1
Unit 3
Id 118
Question linked lists are not suitable to for the implementation of_______________
A insertion sort
B radix sort
C polynomial manipulation
D binary search
Answer D
Marks 1
Unit 3
Id 119
Question Run time polymorphism can be achieved with____________
A virtual base class
B container class
C virtual function
D a &c
Answer C
Marks 1
Unit 3
Id 120
Question When a virtual function is redefine by the derived class, it is called______
A Overloading
B Overriding
C Rewriting
D all of the above
Answer A
Marks 1
Unit 3
Id 121
Question An abstract class is useful when

A no classes should be derived from it.

B there are multiple paths from one derived class to another.


C no objects should be instantiated from it.
D you want to defer the declaration of the class.
Answer C
Marks 1
Unit III
Id 122
Question Use of virtual functions implies
A Overloading
B Overriding
C Static binding
D Dynamic binding
Answer D
Marks 1
Unit III
Id 123
Question Which of the following type casts will convert an Integer variable named amount to a
Double type?
A (double) amount
B ( int to double) amount
C int to double(amount)
D int (amount) to double
Answer A
Marks 1
Unit III
Id 124
Question Pure virtual functions
A Have to be redefined in the inherited class
B Cannot have public access specification
C Are mandatory for a virtual class
D None of the above
Answer A
Marks 1
Unit III
Id 125
Question A friend function to a class, C cannot access
A Private data members and member functions
B Public data members and member functions
C Protected data members and member functions
D The data members of the derived class of C
Answer D
Marks 1
Unit III
Id 126
Question The function whose prototype is void getData(Item *thing); receives
A a pointer to a structure
B a reference to a structure
C a copy of a structure
D None
Answer A
Marks 1
Unit III
Id 127
Question 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
Answer C
Marks 1
Unit III
Id 128
Question What is the output of the following code
char symbol[3]={„a‟,„b‟,„c‟};
for (int index=0; index<3; index++)
cout <<symbol [index];
A abc
B “abc”
C abc
D „abc‟
Answer C
Marks 1
Unit III
Id 129
Question Predict output of the following program
#include<iostream>
using namespace std;

class Base
{
public:
virtual void show() { cout<<" In Base \n"; }
};

class Derived: public Base


{
public:
void show() { cout<<"In Derived \n"; }
};

int main(void)
{
Base *bp = new Derived;
bp->show();

Base &br = *bp;


br.show();

return 0;
}

A In Base
In Base

B In Base
In Derived

C In Derived
In Derived

D In Derived
In Base

Answer C
Marks 2
Unit III
Id 130
Question Output of following program
#include<iostream>
using namespace std;

class Base
{
public:
virtual void show() { cout<<" In Base \n"; }
};

class Derived: public Base


{
public:
void show() { cout<<"In Derived \n"; }
};

int main(void)
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
bp = &b;
bp->show();
return 0;
}
A In Base
In Base

B In Base
In Derived

C In Derived
In Derived

D In Derived
In Base

Answer D
Marks 2
Unit III
Id 131
Question Which of the following is true about pure virtual functions?
1) Their implementation is not known in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes abstract class and an
instance of this class cannot be created.
A Only 1
B Only 2
C Both
D None
Answer C
Marks 1
Unit III
Id 132
Question #include<iostream>
using namespace std;

class Base
{
public:
virtual void show() = 0;
};

int main(void)
{
Base b;
Base *bp;
return 0;
}

A There are compiler errors in lines "Base b;" and "Base bp;"

B There is compiler error in line "Base b;"

C There is compiler error in line "Base bp;"

D No compilation error
Answer B
Marks 2
Unit III
Id 133
Question Predict the output of following program.
#include<iostream>
using namespace std;
class Base
{
public:
virtual void show() = 0;
};

class Derived : public Base { };

int main(void)
{
Derived q;
return 0;
}
A Compiler Error: there cannot be an empty derived class

B Compiler Error: Derived is abstract

C No compiler Error

D None
Answer B
Marks 2
Unit III
Id 134
Question #include<iostream>
using namespace std;

class Base
{
public:
virtual void show() = 0;
};

class Derived: public Base


{
public:
void show() { cout<<"In Derived \n"; }
};

int main(void)
{
Derived d;
Base &br = d;
br.show();
return 0;
}

A Compiler Error in line "Base &br = d;"

B Empty output
C In derived
D None
Answer C
Marks 2
Unit III
Id 135
Question Can a constructor be virtual? Will the following program compile?
#include <iostream>
using namespace std;
class Base {
public:
virtual Base() {}
};
int main() {
return 0;
}
A Yes
B No
C
D
Answer B
Marks 2
Unit III
Id 136
Question Can a destructor be virtual? Will the following program compile?
#include <iostream>
using namespace std;
class Base {
public:
virtual ~Base() {}
};
int main() {
return 0;
}
A Yes
B No
C
D
Answer A
Marks 2
Unit III
Id 137
Question Predict the output

#include<iostream>
using namespace std;
class Base {
public:
Base() { cout<<"Constructor: Base"<<endl; }
virtual ~Base() { cout<<"Destructor : Base"<<endl; }
};
class Derived: public Base {
public:
Derived() { cout<<"Constructor: Derived"<<endl; }
~Derived() { cout<<"Destructor : Derived"<<endl; }
};
int main() {
Base *Var = new Derived();
delete Var;
return 0;
}

A Constructor: Base
Constructor: Derived
Destructor : Derived
Destructor : Base

B Constructor: Base
Constructor: Derived
Destructor : Base

C Constructor: Base
Constructor: Derived
Destructor : Derived

D Constructor: Derived
Destructor : Derived
Answer A
Marks 2
Unit III
Id 138
Question Can static functions be virtual? Will the following program compile?
#include<iostream>
using namespace std;

class Test
{
public:
virtual static void fun() { }
};
A Yes
B No
C
D
Answer B
Marks 2
Unit III
Id 139
Question Predict the output of following C++ program. Assume that there is no alignment and a
typical implementation of virtual functions is done by the compiler.
#include <iostream>
using namespace std;

class A
{
public:
virtual void fun();
};

class B
{
public:
void fun();
};

int main()
{
int a = sizeof(A), b = sizeof(B);
if (a == b) cout <<"a == b";
else if (a >b) cout <<"a >b";
else cout <<"a <b";
return 0;
}
A a>b
B a==b
C a<b
D Compile time error
Answer A
Marks 2
Unit III
Id 140
Question #include <iostream>
using namespace std;

class A
{
public:
virtual void fun() { cout <<"A::fun() "; }
};

class B: public A
{
public:
void fun() { cout <<"B::fun() "; }
};

class C: public B
{
public:
void fun() { cout <<"C::fun() "; }
};

int main()
{
B *bp = new C;
bp->fun();
return 0;
}
A a::fun()
B b::fun()
C c::fun()
D None
Answer C
Marks 2
Unit III

Id 141
Question Predict the output of following C++ program
#include<iostream>
using namespace std;

class Base
{
public:
virtual void show() { cout<<" In Base \n"; }
};

class Derived: public Base


{
public:
void show() { cout<<"In Derived \n"; }
};

int main(void)
{
Base *bp = new Derived;
bp->Base::show(); // Note the use of scope resolution here
return 0;
}
A In Base
B In derived
C Compile time error
D Runtime error
Answer A
Marks 2
Unit III

Id 142
Question Which of the following is true about this pointer?
A It is passed as a hidden argument to all function calls

B It is passed as a hidden argument to all non-static function calls

C It is passed as a hidden argument to all static functions


D None
Answer B
Marks 1
Unit III

Id 143
Question What is the use of this pointer?
A When local variable‟s name is same as member‟s name, we can access member using this
pointer.

B To return reference to the calling object

C Can be used for chained function calls on an object


D All
Answer D
Marks 1
Unit III

Id 144
Question Predict the output of following C++ program.
#include<iostream>
using namespace std;

class Test
{
private:
int x;
public:
Test(int x = 0) { this->x = x; }
void change(Test *t) { this = t; }
void print() { cout <<"x = " <<x <<endl; }
};

int main()
{
Test obj(5);
Test *ptr = new Test (10);
obj.change(ptr);
obj.print();
return 0;
}
A X=5
B X=10
C Compile time error
D Run time error
Answer C
Marks 2
Unit III

Id 145
Question A static data member is given a value
A Within the class definition
B Outside the class definition
C When the program is exeuted
D Never
Answer D
Marks 1
Unit III

Id 146
Question 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
Answer B
Marks 1
Unit III
Id 147
Question A ……………. takes a reference to an object of the same class as itself as an argument.
A Reference constructor
B Copy Constructor
C Self Constructor
D None of the above
Answer B
Marks 1
Unit III
Id 148
Question Automatic initialization of object is carried out using a special member function called
A Friend
B Casting
C Reference Parameter
D Constructor
Answer D
Marks 1
Unit III
Id 149
Question Which of the following condition is true for an object used as a function argument?
i) A copy of the entire objects is passed to the function.
ii) Only the address of the object is transferred to the function.

A Only i
B Only ii
C Both I &ii
D None
Answer C
Marks 1
Unit III
Id 150
Question Which of the following parameter passing mechanism is/are supported by C++ not C
A Pass by value
B Pass by reference
C Pass by value result
D All of above
Answer B
Marks 1
Unit III

You might also like