Pointer

What is pointer?
Pointer is actually a variable which points to another variable by address not value

notation is simple just a asterisk before the variable name

Example:

suppose
int live=20;
int *zaki=&live; //here i am pointing *zaki to a variable address of live
so *zaki is a pointer

now we want to print what actually shows

if we write these line
printf(“zaki = %d”,*zaki);

Output will be: 20 //the value of live

And if we print
printf(“zaki = %d”,zaki);
Output will be: 2686744 //the address of memory location of  the variable live

#include<stdio.h>

int main()
{
int live=20;
int *zaki=live;

printf("zaki = %d",*zaki);

return 0;
}

Another example from subeen vaia’s book:

#include<iostream>
using namespace std;
int main()
{
    int x = 10;
    int *p;
    p=&x;
    cout<<"value of x: "<<x<<endl;
    *p=20;
    cout<<"value of x:"<<x<<endl;
    cout<<"address of x:"<<&x<<endl;
    cout<<"value of p:"<<p<<endl;

return 0;
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.