Professional Documents
Culture Documents
ADRESS OF OPERATOR”&”:
//adress cannot be store in any data type otherthan pointers
//double pointer point toward the site wherer double is stored
//every bite has an adress
#include<iostream>
#include<conio.h>
using namespace std ;
int main()
{
int var1=11;
int var2=22;
int var3=33;
cout<<&var1<<endl;
cout<<&var2<<endl;
cout<<&var3<<endl;
system("pause");
return 0;
}
OUTPUT:
POINTER VARIABLES:
#include<iostream>
#include<conio.h>
using namespace std ;
int main()
{
int var1=11;
int var2=22;
int var3=33;
int *ptr;
double var4=33.9;
double *ptr2;
ptr=&var1;
cout<<ptr<<endl;
ptr=&var2;
cout<<ptr<<endl;
ptr =&var3;
cout<<ptr<<endl;
ptr2=&var4;
cout<<ptr2<<endl;
system("pause");
return 0;
}
OUTPUT:
CONTENT OF OPERATOR:
#include<iostream>
#include<conio.h>
using namespace std ;
int main()
{
int var1=11;
int var2=22;
int var3=33;
int *ptr;
double var4=33.9;
double *ptr2;
ptr=&var1;
cout<<var1<<endl;
cout<<ptr<<endl;
cout<<*ptr<<endl;
ptr=&var2;
cout<<var2<<endl;
cout<<ptr<<endl;
cout<<*ptr<<endl;
ptr =&var3;
cout<<var3<<endl;
cout<<ptr<<endl;
cout<<*ptr<<endl;
ptr2=&var4;
cout<<var4<<endl;
cout<<ptr2<<endl;
cout<<*ptr2<<endl;
system("pause");
return 0;}
OUTPUT:
POINTER ARRAY:
#include<iostream>
#include<conio.h>
using namespace std ;
int main()
{
int var1[5]={1,2,3,4,5};
cout<<var1[0]<<endl;
int *ptr;
ptr=var1;
for(int i=0;i<5;i++)
cout<<*(ptr+i)<<endl;
for(int i=0;i<5;i++)
cout <<*ptr++<<endl;
system("pause");
return 0;}
OUTPUT:
POINTERS AND
FUNCTION:
#include<iostream>
#include<conio.h>
using namespace
std ;
void
centimize(double
&v)//change by
reference therefore
we have use &
{
v*=2.54;
int main()
{
double var=10.0;
cout<<"var:"<<var<<"inches"<<endl;
cout<<endl;
centimize(var);
cout<<"var:"<<var<<"centimeters"<<endl;
cout<<endl;
system("pause");
return 0;
}
OR
#include<conio.h>
using namespace std ;
void centimize(double *ptrd)//change by reference therefore we have use &
{
*ptrd=2.54;
int main()
{
double var=10.0;
cout<<"var:"<<var<<"inches"<<endl;
cout<<endl;
centimize(&var);
cout<<"var:"<<var<<"centimeters"<<endl;
cout<<endl;
system("pause");
return 0;
}
OUTPUT:
FUNCTIONS AND ARRAY:
#include<iostream>
#include<conio.h>
using namespace std ;
void centimize(double *ptrd)//change by reference therefore we have use &
{
for (int i=0;i<5;i++)
*ptrd+++=2.54;
int main()
{
double array[5]={1,2,3,4,5};
centimize(array);
for(int i=0;i<=5;i++)
cout<<"array["<<i<<"]"<<array[i]<<"centimize"<<endl;
system("pause");
return 0;
}
OUTPUT: