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
67 views
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/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

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

5.

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

6.

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;
or
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 :

#include<iostream.h>
#include<conio.h>
void main()
{
int a;
int *ptr;
clrscr();
ptr=&a;
cout<<"\nAddress of a:"<<ptr;
cout<<"\nAfter incrementing address value ";
ptr+=2;
cout<<"address of a:"<<ptr;
getch();
}

Output :

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

 Goeduhub:

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