Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
Online Training - Youtube Live Class Link
0 like 0 dislike
in C Programming by Goeduhub's Expert (7.1k points)

Pointers in C++

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-


Course Name

Apply Coupon


Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon


Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon


Complete Machine Learning & Data Science with Python Apply Coupon


Natural Language Processing-NLP with Deep Learning in Python Apply Coupon


Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon


Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
Best answer

Pointers in C++

Pointers is one of the key aspects of C++ language similar to that of C. As we know, pointers offer a unique approach to handle data in C and C++.

Declaration and Initializing Pointers

1. Declaration of Pointer

The declaration of a pointer is based on the data type of the variable it points to.

Syntax :

data_type *pointer_variable;

Here pointer variable is the name of the pointer and the data-type refers to one of the valid C++ data types. The data type is followed by an asterisk(*) symbol, which distinguishes a pointer variable from other variables to the compiler.

Note : We can locate asterisk(*) immediately before the pointer variable, or between the data type and the pointer variable, or immediately after the data type. It does not cause any effect in the execution process.

Example :

int *ptr;
int* ptr;

Here ptr is a pointer variable and points to a integer variable.

2. Initialization of Pointer

The pointer variable should contain the memory location of any variable of it's own type. In the above example ptr should contain memory location of an integer variable.

We can initialize a pointer variable as follows :

int *ptr;  //Declaration
int a;
ptr=&a;  //Initialization

The pointer variable ptr contains address of variable a. Here we used '&' to retrieve address of a.

Program :

void main()
int a;
int *ptr;
cout<<"\nAddress of a:"<<ptr;
cout<<"\nAfter incrementing address value ";
cout<<"address of a:"<<ptr;

Output :

Our Mentors(For AI-ML)

Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune


Ms. Nisha

An alumna of IIT-BHU


About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © Social::   |  |