100% found this document useful (1 vote)
236 views2 pages

Mock Test Question and Ans C ++ SASTRA University

The document contains 15 multiple choice questions about pointers, arrays, classes, inheritance, and friend functions in C++. Key points covered include: - A pointer stores the address of a variable. - Arrays can be dynamically allocated using pointers. - Friend functions can access private members of a class without being a member of the class. - Abstract classes are useful when no objects should be instantiated from the class.

Uploaded by

star
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
100% found this document useful (1 vote)
236 views2 pages

Mock Test Question and Ans C ++ SASTRA University

The document contains 15 multiple choice questions about pointers, arrays, classes, inheritance, and friend functions in C++. Key points covered include: - A pointer stores the address of a variable. - Arrays can be dynamically allocated using pointers. - Friend functions can access private members of a class without being a member of the class. - Abstract classes are useful when no objects should be instantiated from the class.

Uploaded by

star
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/ 2

Answers

1. Write a definition for a variable of type pointer-to-float.


Ans: float *fptr
2. Write a code snippet for creating a 2d array dynamically.
Ans:
3. 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.
4. The expression *test can be said to
a. be a pointer to test.
b. refer to the contents of test.
c. dereference test.
5. Of the three ways to pass arguments to functions, only passing by __________ and
passing by __________ allow the function to modify the argument in the calling
program.
Ans: reference, address
6. 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.
7. Say True or false: A pointer to a base class can point to objects of a derived class.
Ans: False
8. Write a declarator for a virtual function called dang() that returns type void and takes one
argument of type int.
Ans: virtual void dang(int); or void virtual dang(int);
9. 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) takes no arguments.
10. 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.
11. Say True or false: A friend function can access a class’s private data without being a
member of the class.
Ans: true
12. Say True or false: The user must always define the operation of the copy constructor.
Ans: false; the compiler provides a default copy constructor
13. Say True or false: A copy constructor could be defined to copy only part of an object’s
data.
Ans: true : true, if there was a reason to do so
14. 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 of the above
15. How can me make a function to operate on objects of two different classes? a) If the
classes are inherited from same base class then we can put the function in base class to
make it possible
b) if classes are unrelated then friend function can be used as a bridge between two
classes.
c) both a and b.
d) None of the above

You might also like