-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Thursday, 8 October 2015

Pointer Declaration in C++

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:


DataType *var;

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( );
}

Output

Concept of pointers


No comments:

Post a Comment