C++:Pointers|Declaration of pointer variable

Declaration of pointer variable

Syntax:
datatype *pointervariable;

Example:

int *p;
char *c;
char *name;
int *abc;
float *d;

Example:

int a=10;
int *p;
p=&a;

a “a” is a normal int variable that can store an integer value
p “p” is an integer type pointer variable so it can store the address of another variable of type integer.
Thus we can write
P=&a;

Difference between:int *p; and *p;

int *p; “p” is an integer type pointer variable that can store the address of another variable of type integer.
*p Value at p. i.e. value at address stored at p.
#include<iostream>
using namespace std;
int main()
{
	int a=10;
	int *p;
	p=&a;
	cout<<"value of a "<<a<<endl;
	cout<<"address of a "<<&a<<endl;
	cout<<"value stored at a "<<*(&a)<<endl;
	cout<<"value stored at p "<<p<<endl;
	cout<<"value at p (value at address stored at p) "<<*p<<endl;
	cout<<"address of p "<<&p<<endl;
	return(0);
}

Output:

value of a 10
address of a 0x6ffe0c
value stored at a 10
value stored at p 0x6ffe0c
value at p (value at address stored at p) 10
address of p 0x6ffe00