Pointer Declaration
As I have discussed in the previous blog that a pointer is a variable whose value is the address of another variable.Remember that the declaring a pointer is same as declaring a simple variable.An asterisk "*" is used in the declaration that indicates that the variable is a pointer variable.
Syntax
The syntax of declaring a pointer is as follows:
Example
int *p;
Now,I will demonstrate this concept by a simple program.
Source code
#include<iostream>
#include<conio.h>
using namespace std;
void main( )
{
int n;
int *ptr; // it indicates that "ptr" is a pointer
cout<<"Enter an integer";
cin>>n;
ptr=&n;
cout<<"The value of n:"<<n<<endl;
cout<<"The address of n:"<<ptr<<endl;
getch( );
}
No comments:
Post a Comment