Pointers are used to access array elements, pass arguments to functions by reference, pass arrays and strings to functions, obtain memory from the system, and create data structures like linked lists. Memory addresses refer to the locations where variables are stored. A pointer variable stores the address of another variable. The indirection operator (*) is used to dereference a pointer and access the value of the variable it points to. A void pointer can point to data of any type.
A recursive function is a function that calls itself. A recursive function is used for repeating code. If the state of the function does not change, and it has no preset exit condition that is reached, a recursive call can turn into an infinite loop.
A recursive function is a function that calls itself. A recursive function is used for repeating code. If the state of the function does not change, and it has no preset exit condition that is reached, a recursive call can turn into an infinite loop.
This slide will help you to learn Pointer assignments, Pointer arithmetic,Pointer comparisons, Pointers & arrays, Arrays of pointers, Multiple indirection
This presentation focus on the basic concept of pointers. so that students can easily understand. it also contains basic operations performed by pointer variables and implementation using c language.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
c++ pointers by Amir Hamza Khan (SZABISTIAN)Ameer Hamxa
This slides will help you to learn pointers in c++ and i have put in some programs in this slides to help beginners in c++ and also you can use it as your own presentation lol ;)
follow me on facebook https://www.facebook.com/Ameerii132
and you are welcome for questions and quirries
This slide will help you to learn Pointer assignments, Pointer arithmetic,Pointer comparisons, Pointers & arrays, Arrays of pointers, Multiple indirection
This presentation focus on the basic concept of pointers. so that students can easily understand. it also contains basic operations performed by pointer variables and implementation using c language.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
c++ pointers by Amir Hamza Khan (SZABISTIAN)Ameer Hamxa
This slides will help you to learn pointers in c++ and i have put in some programs in this slides to help beginners in c++ and also you can use it as your own presentation lol ;)
follow me on facebook https://www.facebook.com/Ameerii132
and you are welcome for questions and quirries
2. What are Pointers Used For?
Accessing array elements
Passing arguments to a function when the function needs
to modify the original argument
Passing arrays and strings to functions
Obtaining memory from the system
Creating data structures such as linked lists
8. Memory and Addresses
Addresses Locations
1270
1271
int IntVar1 = 25; 25 IntVar1
1272
int IntVar2 = 11; 1273
1274
11 IntVar2
1275
Contents/Data
9.
10. Memory and Addresses
In some cases we may be interested in knowing the address
where our variable is being stored during runtime.
The address that locates a variable within memory is what
we call a reference to that variable.
e.g.,
& IntVar;
Address-of/reference
When preceding the name of the variable “IntVar” with the
operator
reference operator (&) we are no longer talking about the
content of the variable itself, but about its reference (i.e., its
address in memory).
11. Memory and Addresses
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int IntVar1;
int IntVar2;
cout << &IntVar1 << endl //print the addresses
<< &IntVar2 << endl;
getch();
return 0; }
12. Pointer Variable
The variable that stores the reference to another variable is
what we call a pointer.
e.g.,
ptr &InVar;
13. Pointer Variable
The variable that stores the reference to another variable is
what we call a pointer.
e.g.,
Pointer-to Pointer/Pointer-variable
int * ptr; //variable “ptr” as a pointer-to “int”
ptr &InVar;
14. Accessing Addresses
int main()
{ int IntVar1 = 25;
int IntVar2 = 11;
int* ptr; //pointer to integers
ptr = &IntVar1; //pointer points to IntVar1
cout << ptr << endl //print the address of IntVar1
ptr = &IntVar2
cout << ptr << endl //print the address of IntVar2
getch();
return 0; }
15. int* ptr; 1270
ptr = &IntVar1; ptr
1271
cout << ptr ;
1271
25 IntVar1
1272
ptr points-to to the
1273
address of IntVar1
1274
11
1275 IntVar2
1270
1271
25
1272 IntVar1
int* ptr; ptr 1273
ptr = &IntVar2;
1274 1274
cout << ptr ;
11
ptr points-to to the 1275 IntVar2
address of IntVar2
16. Accessing Contens
int main()
{ int IntVar1 = 25;
int IntVar2 = 11;
int* ptr; //pointer to integers
ptr = &IntVar1; //pointer points to IntVar1
cout << *ptr << endl //print the content of IntVar1
ptr = &IntVar2
cout << *ptr << endl //print the content of IntVar2
getch();
return 0; }
17. ptr
int* ptr;
ptr = &IntVar1; 25 IntVar1
*ptr is 25
cout << *ptr ;
11
deference /indirection operator.
IntVar2
Expression *ptr means the value of
the variable pointed to by ptr.
25
IntVar1
ptr
int* ptr;
ptr = &IntVar2; 11
*ptr is 11
IntVar2
cout << *ptr ;
18. Pointer to Void
The address that is put in a pointer variable must be the
same type as the pointer, for example, the address of a float
variable can’t be assigned to a pointer to int.
float floVar = 25.67;
int* ptrInt = &floVar;
19. Pointer to Void
The address that is put in a pointer variable must be the
same type as the pointer, for example, the address of a float
variable can’t be assigned to a pointer to int.
float floVar = 25.67;
int* ptrInt = &floVar; //ERROR: can’t assign float* to int*
20. Pointer to Void
The address that is put in a pointer variable must be the
same type as the pointer, for example, the address of a float
variable can’t be assigned to a pointer to int.
float floVar = 25.67;
int* ptrInt;
ptrInt = &floVar; //ERROR: can’t assign float* to int*
Exception to that case is a general-purpose pointer that can
point to any data type, e.g.,
void* ptrVoid; //pointer to void
21. Pointer to Void
The address that is put in a pointer variable must be the
same type as the pointer, for example, the address of a float
variable can’t be assigned to a pointer to int.
float floVar = 25.67;
int* ptrInt;
ptrInt = &floVar; //ERROR: can’t assign float* to int*
Exception to that case is a general-purpose pointer that can
point to any data type, e.g.,
void* ptrVoid; //pointer to void
ptrVoid = &floVar; //OK