MCQ with answers for (OOP) | Object Oriented Programming | 22316 [Pointers] MSBTE

Subject subject details
Program: Diploma in Computer engineering
Program Code CO
Scheme I
Semester 3
Course: Object Oriented Programming
Course Code 22316

1. Which of the following is the correct way to declare a pointer ?

A. int *ptr

B. int ptr

C. int &ptr

D. All of the above Answer:A

2. Which of the following gives the [value] stored at the address pointed to by the pointer : ptr?

A. Value(ptr)

B. ptr

C. &ptr

D. *ptr Answer:D


3. A pointer can be initialized with

A. Null

B. Zero

C. Address of an object of same type

D. All of the above Answer:D


4. 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 pointers to string types

D. none of the above Answer:A

5. Generic pointers can be declared with .

A. auto

B. void

C. asm

D. None of the above Answer:B


6. Which from the following is not a correct way to pass a pointer to a function?

A. Non-constant pointer to non-constant data

B. A non-constant pointer to constant data

C. A constant pointer to non-constant data

D. All of the above Answer: D


7. Referencing a value through a pointer is called

A. Direct calling

B. Indirectio

C. Pointer referencing

D. All of the above 

Answer:B


8. 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 pointers to string types

d) y is a pointer to a string Answer:A


9. 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 type Answer:D


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


11. What will happen in the following C++ code snippet?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


12. What will be the output of the following C++ code?#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


13. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char andreturns 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

Explanation: Function that takes pointer to a float, a pointer to a pointer to a char and returns apointer to a pointer to a integer is int **fun(float*, char**).


14. What is size of generic pointer in C++ (in 32-bit platform)?

a) 2

b) 4

c) 8

d) 0

Answer: B

Explanation: Size of any type of pointer is 4 bytes in 32-bit platforms.


15. What will be the output of the following C++ code?

#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) << [1[a]];

return 0;

a) 15 18 21

b) 21 21 21

c) 24 24 24

d) Compile time error Answer: B


Explanation: a[1][2] means 1 * (4)+2 = 6th element of an array starting from zero.


16. What will be the output of the following C++ code?

#include

<iostream>

using namespace std;int main() {

int i;

const char *arr[] = {"c", "c++", "java", "VBA"};const char

*(*ptr)[4] = &arr; cout << ++(*ptr)[2];

return 0;

}

a) ava

b) java

c) c++

d) compile time error Answer: A

Explanation: In this program we are moving the pointer from first position to second position and printing the remaining value.


17. The void pointer can point to which type of objects?

a) int

b) float

c) double

d) all of the mentioned 

Answer: D

Explanation: Because it doesn‟t know the type of object it is pointing to, So it can point to all objects.


18. 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) using shift keyword 

Answer: B

Explanation: By casting the pointer to another data type, it can be dereferenced from the void pointer. 

19. A non-member function that is given access to all members of a class within it is declared, is called

a. Access function

b. Friend function

c. Operator functions

d. None of them 

Answer:B


20. There are how many different ways to pass a pointer to a function?

a. 1 

b.2

 c.3

 d.4

Answer:D


21. A void pointer cannot point to which of these?

A. Methods in c++

B. Class member in c++

C. Both A & B

D. None of the above

Answer : B

Explanation: Because the class member will have a definite type, So it cannot pointed by avoid pointer.

22. The correct statement for a function that takes pointer to a float, a pointer to a pointer toa 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

Explanation: The correct statement for a function that takes pointer to a float, a pointer to apointer to a char and returns a pointer to a pointer to a integer is int ***fun(float*, char**).

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

Explanation: dp is initialized int value of i.

24. 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 type Answer: D

Explanation: A pointer can be in only 3 states a,b and c.

25.A pointer contains .

A. Address of a variable

B. Name of the variable

C. Value of the variable

D. None of the above Answer: A


26.  Assigning reference to an object  a.Will create another copy of the object

b. Will create two different copies of the object

c. Will not create any other copy of the object

d. Will not refer to the object

Answer: C


27. Which is correct syntax for declaring pointer to object? 

a.className* objectName;

b.className objectName;

 c.*className objectName; 

d.className objectName(); 

 Answer: A

28. Which operator should be used to access the members of the class using object pointer?a.Dot operator

 b.Colon to the member 

c.Scope

D.resolution operatord.Arrow operator

Answer:D


29. How does compiler decide the intended object to be used, if more than one object are used?

a.Using object name

 b.Using an integer pointer

 c.Using this pointer

 d.Using void pointer

Answer:C


30. If pointer to an object is declared,  

a.It can store any type of address

b. It can store only void addresses

c. It can only store address of integer type

d. It can only store object address of class type specified Answer:D


31. Polymorphism is achieved through 

a. Heritance

b. Poly programming

c. Encapsulation

d. Overloading

 Answer:D


32. The mechanism of giving special meaning to an operator is called 

(A) Object

(B) Inheritance

(C) Function overloading

(D) Operator Overloading Answer:D


33. In function overloading do not use the function name for two unrelated functions.

(A) Same

(B) Different

(C) Similar

(D) Complement Answer: A


34. The operator must have at least one operand of user defined type.

(A) New

(B) Overloaded

(C) Existing

(D) Binary Answer: B


35. Which of the following operators cannot be overloaded?

(A) +

(B) ++

(C) --

(D) :: Answer: D


36. Which one is the best description of polymorphism?

A. It is the ability for undefined message/data to be processed in at least one way

B. It is the ability for a message/data to be processed in more than one form

C. It is the ability for many messages/data to be processed in many ways

D. none of these Answer: B


37. The languages that support classes but not polymorphism is called?

A. child Class-based language

B. Class-based language

C. Object-based language

D. Procedure Oriented language Answer: C


38. Which type of function shows polymorphism among the following?

A. Inline function

B. Virtual function

C. Undefined functions

D. Class member functions Answer: B


39. Which one of the following can show polymorphism?

A. Overloading ||

B. Overloading &&

C. Overloading <<

D. Overloading +

Answer: C


40. The problem may arise if we use abstract class functions for polymorphism in OOP?

A. All classes are converted as an abstract class

B. All the derived classes must implement the undefined functions

C. abstract class must have derived a class

D. Derived classes can‟t redefine the functionAnswer: C


41. If two classes derive one base class and redefine a function of the base class, also overloadsome operators inside the body of the class. Among these two things of function and operator overloading, the polymorphism is used where?

A. Function overloading only

B. Operator overloading only

C. Either function overloading or operator overloading because polymorphism can be applied onlyonce in a program

D. Both of these are using polymorphism Answer:C


42. Run time polymorphism is achieved only when a............................................... Is accessed through a pointer to the base class.

A) static function

B) Real function

C. Member function


43. A class serves as base class for many derived classes it is called:

A. polymorphism

B. multipath inheritance C .hierarchical inheritance

C. none of these 

Answer: C


44. Compile time polymorphism in C++ language area.Operator overloading

b.Function overloading

c.Function overriding

d.B Only

e.A & B Answer: E


47. Which of the following cannot be overloaded in C++? 

a.Increment operator

b.Constructor 

c.Destructor

d.New and delete operator Answer: C


48. Which is the correct declaration of pure virtual function in C++

a.virtual void func = 0;r: B

b.virtual void func() = 0; c.virtual void func(){0};

d.void func() = 0; 

Answe


49. In a class, pure virtual functions in C++ is used

a.To create an interface

b.To make a class abstract

c.To force derived class to implement the pure virtual functiond

d .All the above

Answer: D


download

Comments

Popular posts from this blog

Getting started with c programming (step-by-step) explanation

22413 software engineering notes [ ⚠️] pdf | Msbte 4th semester diploma

22620 Network and Information Security NIS solved lab manual pdf