KEMBAR78
Pointer | PDF | Pointer (Computer Programming) | Variable (Computer Science)
0% found this document useful (0 votes)
23 views13 pages

Pointer

Chapter six discusses pointers in C++, which are variables that hold the address of another variable, allowing for memory address manipulation and dynamic data structure creation. It explains pointer declaration syntax, the use of reference and dereference operators, and highlights the advantages and uses of pointers in programming. Key benefits include improved execution time, memory management, and the ability to return multiple values from functions.

Uploaded by

Samson Girma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Pointer

Chapter six discusses pointers in C++, which are variables that hold the address of another variable, allowing for memory address manipulation and dynamic data structure creation. It explains pointer declaration syntax, the use of reference and dereference operators, and highlights the advantages and uses of pointers in programming. Key benefits include improved execution time, memory management, and the ability to return multiple values from functions.

Uploaded by

Samson Girma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Chapter six

POINTERS IN C++
This Unit covers
The pointers in C++ programming language is
basically a variable that is also called as locater
or installer that generally point towards the
address of a provided value.

What are Pointers?
In C++, a pointer refers to a variable that holds the address of
another variable.
Like regular variables, pointers have a data type.
For example, a pointer of type integer can hold the address of a
variable of type integer.
A pointer of character type can hold the address of a variable of
character type.
What are Pointers?
 You should see a pointer as a symbolic
representation of a memory
address. With pointers, programs can simulate call-
by-reference.
They can also create and manipulate dynamic data
structures.
In C++, a pointer variable refers to a variable
pointing to a specific address in a memory pointed by
another variable.
Addresses in C++
To understand C++ pointers, you must understand how computers store
data.
 When you create a variable in your C++ program, it is assigned some
space the computer memory. The value of this variable is stored in the
assigned location.
 To know the location in the computer memory where the data is stored,
C++ provides the & (reference) operator. The operator returns the address
that a variable occupies.
For example, if x is a variable, &x returns the address of the variable.
Pointer Declaration Syntax
The declaration of C++ takes the following syntax:
datatype *variable_name;
 The datatype is the base type of the pointer which must
be a valid C++ data type.
 The variable_name is should be the name of the pointer
variable.
Asterisk used above for pointer declaration is similar to
asterisk used to perform multiplication operation. It is the
asterisk that marks the variable as a pointer.
Pointer Declaration Syntax
Here is an example of valid pointer declarations in C++:

int *x; // a pointer to integer


double *x; // a pointer to double
float *x; // a pointer to float
char *ch // a pointer to a character
Reference operator (&) and Deference
operator (*)
 The reference operator (&) returns the variable’s address.
The dereference operator (*) helps us get the value that
has been stored in a memory address.
 For example:
 If we have a variable given the name num, stored in the
address 0x234 and storing the value 28.
 The reference operator (&) will return 0x234.
 The dereference operator (*) will return 5.
EXAMPLE
Advantages of Pointer
Less time in program execution.
 Working on the original variable.
 With the help of pointers, we can create data structures (linked-
list, stack, queue).
 Returning more than one values from functions.
 Searching and sorting large data very easily.
 Dynamically memory allocation.
Uses of Pointers
To pass arguments by reference.
 For accessing array elements.
 To return multiple values.
 Dynamic memory allocation.
 To implement data structures.
 To do system level programming where memory
addresses are useful.
Thank You

You might also like