Pointer refers to variable that hold the address of another variable or memory location
Pointer hold the address of same type
Char can hold char int can store int address
& used to store address
code:
#include <iostream>
using namespace std;
int main(){
int *p;
int a;
a=2000;
p = &a;
cout<<"Address of a: "<<&a<<endl;
cout<<"Address of a: "<<p<<endl;
cout<<"Address of p: "<<&p<<endl;
cout<<"Value of a: "<<*p;
return 0;
}
output:
Address of a: 0x78fe14
Address of a: 0x78fe14
Address of p: 0x78fe18
Value of a: 2000
explaination:
Adress of a and p will be the same because we refers the value of a to &p and &p is showing in third line it store nothing but address of a and value is stored to *p;
No comments:
Post a Comment