Pointer In C++

pointer
pointer

Pointer In C++:-

In this article I have explained Pointer in c++ in detail with effective way.You will like it , I know about it. So enjoy it lovely friends. The concept of pointer  in c++ is most important to get c++ in detail.

Pointer:-

It is a variable contains the address of another variable of same type. Pointer is a special type of variable.

If we want to Store the address of ’int’ Type variable then we have to take ‘int’ type of pointer variable.

Pointer Variable Declaration Statement:-

Syntax ,

DataType         * VariableName;

In this Statement, we declare the data type and the name of a Pointer variable.

Example,

int    *ptr;

Initialization of a Pointer:-

To initialize a Pointer variable, first of all we have to declare the same type of a Simple variable.

Example,

int a;

a=10;

Now we have to do initialization of example  Pointer,

ptr=&a;

By above Statement ’ptr’ is initialized,the address of variable ‘a’

If we want to display the value of a then we can write,

cout<<*ptr;

Output,   10

By above example it is declared that Pointer ‘ptr’ now indicating the variable ‘a’ and showing the value of a.

//Program to show the use of a pointer.

#include<iostream.h>

#include<conio.h>

void main ()

{

clrscr ();

int a,*ptr;

a=5;

ptr=&a;

cout<<”the value of variable”<<a;

cout<<” The value of a variable by pointer”<<*ptr;

cout<<”The address of a variable “<<ptr;

getch();

}

Output:-

The value of variable:-5

The value of a variable by Pointer:-5

The address of a variable:- EH5326 (It may any address)

Address of operator (&):-

The operator is used to get the address of a variable. If we want to get the address of a variable namely ‘a’ then we have to write the following Statement.

&a

After this we put it into the same type of variable of Pointer type.

ptr=&a;

Assignment  Operator(=):-

This operator is used to assign a value to a  variable like following Statement.

(1) b=a;

(2) a=5;

In (1) Example the value of ‘a’ is going into variable ‘b’ in

(2) example 5 is putting in variable ‘a’.

 Pointer To A Pointer :-

A variable declared in a Program is assigned an address. A Pointer variable also has an address. Pointer to a Pointer means that a variable can be declared which can store the address of Pointer variable.

//Program to Show the use of ‘Pointer to a Variable’.

#include<iostream.h>

#include<conio.h>

void main ()

clrscr ();

int a=10,   *ptr1, **ptr2;

ptr1=&a;

ptr=&ptr1;

cout<<” The value of a variable is:-”<<a<<”in”;

cout<<”The value of a variable by ptr1 is ”<<*ptr<<”/n”;

cout<<”The value of a variable by ptr2 is”<<**ptr2;

getch();

}

pointer
pointer

I know you will like this post very much.After getting it in your mind please tell me, how it was? Like this post I will provide all stuff like Computer Science , Mathematics , Technology  , Meditation etc.

You Also Can See More Result By Using Google Search.

You Also Can Play Online Quiz by following Link,

Computer Science

You Also Can Ask and Give Answer of Questions by following Link,

Questions

If you have any requirements to know more about it in detail, then this content may be helpful to you.

You Also Can Visit For More Knowledge In C++:-

Visit Your YouTube  Channel:-  Think , About It

Visit Your Website :- www.atozlives.com

Thanks,

“Play With All Computer Science , Mathematics  And Technology.”

 

 

9 COMMENTS

  1. Thanks for your write-up. One other thing is that if you are selling your property yourself, one of the problems you need to be cognizant of upfront is just how to deal with house inspection reviews. As a FSBO seller, the key concerning successfully transferring your property plus saving money upon real estate agent income is expertise. The more you are aware of, the easier your property sales effort will likely be. One area in which this is particularly essential is assessments.

LEAVE A REPLY

Please enter your comment!
Please enter your name here