OOP (313304) Practical No.16:Write programs to implement- Pointer to object
The pointer to objects helps to improve the efficiency of the program and access the objects dynamically.
A pointer is a variable that stores the memory address of another variable (or object) as its value. A pointer aims to point to a data type which may be int, character, double, etc.
Pointers to objects aim to make a pointer that can access the object, not the variables. Pointer to object in C++ refers to accessing an object.
OOP (313304) Practical No.16 Exercise:
1. State output of the following code:
#include <iostream.h>
#include<conio.h>
class myclass
{
int i;
public:
void read(int j)
{
i= j;
}
int getint()
{
return i;
}
};
void main()
{
clrscr();
rnyclass ob, *objectPointer;
objectPointer = &ob;
objectPointer->read(lO);
cout<<objectPointer->getint();
getch();
Answer:
2. Which is the pointer that denotes the object calling the member function?
Answer: b) This pointer
3. A pointer can be initialized with
Answer: All of the above
Practical Related Questions
1 Write a C++ program to declare a class "Book" contammg data members book_name, auther_name, and price . Accept this information for one object of the class using pointer to that object.
Answer:
2 Write a C++ program to declare a class "Box" having data members height, width and breadth. Accept this information for one object using pointer to that object . Display the area and volume of that object.
Answer:
3. Write a C++ program to declare a class birthday having data members day, month, year. Accept this information for five objects using pointer to the array of objects
Answer:
4. Complete the following table:
Answer:
Conclusion
We successfully completed OOP (313304) Practical No.16 and Wrote C++ programs to implement- Pointer to object.