Pointers are used to finds the Memory address of the variables in C++. Pointers are also variables which hold the memory address instead of values. In Programming and complex Data Structures Pointers are used to Pass Value by Reference. In this problem we just get two integers and show their Memory Address.
Source Code
#include <iostream>
using namespace std;
/*
In this programme the value of pointer is Increment with each value.
*/
int main ()
{
cout<<endl<<endl<<"*********** POINTER IN C++ *************"<<endl;
const int max = 3; //iintilize a costant variable with max is 3
int value[max]; //Declarte a array of value with 0,1,2
int *pointer; //Declare a variable taht's initeger type pointer
cout<<endl;
for(int i=0;i<max;i++)
{
cout<<"Enter Value: \t";
cin>>value[i];
}
pointer = value; //all the values are assign to pointer mean memory address
for (int j = 0; j < max; j++)
{
cout << endl << "Value Address"<< j <<" = ";
cout << pointer << endl;
cout << endl << "Value Address"<< j <<" = ";
cout << *pointer << endl;
pointer++;
}
return 0; }
Output of the Program
How to find Memory :p basically it's not a physical :p
ReplyDelete