Object Oriented Programming Assignment # 02: Submitted To
Object Oriented Programming Assignment # 02: Submitted To
Object Oriented Programming Assignment # 02: Submitted To
Pointers:
Pointer is a variable in C++ that holds the address of another variable. They
have data type just like variables, for example an integer type pointer can hold the address of
an integer variable and an character type pointer can hold the address of char variable. Dealing
with these memory addresses in programming is done by pointers. Pointers are extremely
powerful programming tool that can make things easier and help to increase the efficiency of
a program and allow programmers to handle an unlimited amount of data. It is possible for
pointers to dynamically allocate memory, where programmers don't have to worry about how
much memory they will need to assign for each task, which cannot be done/performed without
the concept of a pointer.
Syntax of pointer
data_type *pointer_name;
❖ Implementation of pointers:
There are some important points to implement pointers:
➢ Define a pointer variable
➢ Assigning the address of a variable to a pointer using unary operator (&) which returns the
address of that variable.
➢ Accessing the value stored in the address using unary operator (*) which returns the value
of the variable located at the address specified by its operand.
❖ Source code:
#include<iostream>
using namespace std;
int lareg(int,int);
struct larg{
int *large;
int *xptr;
int *yptr;
};
int main()
{
larg r;
int x,y;
cout<<"Enter the value of
x :";
cin >> x;
cout<<"Enter the value of
y :";
cin>> y;
r.xptr=&x;
r.yptr=&y;
lareg(x,y);
}
int lareg(int a,int b)
{
int large;
if(a>b)
large=a;
else
large=b;
cout<<"The largest
nmuber is :" <<large;
}
Thanks