C++ is one of the most versatile languages in the world. It is used nearly everywhere for everything… systems programming (operating systems, device drivers, database engines, embedded, Internet of Things, etc.)

Enter Header Image Headline Here

Saturday 15 April 2017

C++ Pointer

                                            C++ Pointer


Pointers are powerful feature of C++ that differentiates it from other programming languages like JAVA and Python.

Pointers are used in  C++ program to access the memory  and manipulate the address.


Address in C++


To understand pointers, you should first know how data is stored on the computer.

Each Variable you create in your program is assigned a location in the computer's memory, the value the variable stores is actually stored in the location assigned.

To know where the data is stored, C++ has an & operator.
The & (reference) operator gives you the address occupied by a variable.

If var is a variable then, & var gives the address of that variable.

Example:  Adress in C++









Output:














Note:   


The 0x in the beginning represents the address is in hexadecimal form.

Notice that first address differs from second by 4- bytes and second address differs from third by 4 -bytes,


This is because the size of integer ( variable of type int) is 4 bytes in 64- bit system.


Pointers Variables

C++ gives you the power to manipulate the data in the computer's memory directly. You can assign and de-assign any space in the memory as you wish, This is done using Pointer variables.

Pointer variable are variables that points to a specific address in the memory pointed by another variable.

How to declare a pointer?














The statement above defines a pointer variable p. It holds the memory address.

The asterisk is a dereference operator which means pointer to.

Here, pointer p is a pointer to int i.e., it is pointing to an integer value in the memory address.

0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Text Widget