Code:
//Pointers: A pointer is a variable that contains the address of a variable.
#include<iostream>
using namespace std;
main()
{
int x=100; // initialize integer type variable name x
int *y; // declare integer type pointer y
cout<<x; // print value of integer type variable x
cout<<"\n"; // new line
y=&x; // giving address of variable x to y
*y=5000; // without accessing x changing value of x=100 to 5000
cout<<x; // after, poiting now, value of x is : 5000
cout<<"\n"; // new line
int **z; // declare integer type pointer to pointer c
z=&y; // giving address of y to z
**z=90; // now, without disturbing x&y value of x is 90
cout<<x; //value of x is 90
}
No comments:
Post a Comment