









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Where and how the pointers can be used in c-programming.
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!










Topics
Memory address: 1024 1032
integer (^) pointer
Pointer Types
(^) Pointers to int objects (^) Pointers to char objects
(^) Pointers to pointers to int objects
(^) Usage: &variable_name
Memory address: 1024
int a = 100; //get the value, cout << a; //prints 100 //get the memory address cout << &a; //prints 1024
a
Memory address: 1024 1032
a
b #include
using namespace std; int main(){
int a, b; a = 88;
b = 100; cout << "The address of a is: " << &a << endl;
cout << "The address of b is: " << &b << endl; }
(^) Result is: The address of a is: 1020 The address of b is: 1024
Memory address: 1024 1032
int a = 100; int *p = &a; cout << a << endl; cout << &a << endl; cout << p << " " << *p << endl; cout << &p << endl;
(^) Result is: 100 1024 1024 100 1032
a p
Don’t get confused
(^) Declaring a pointer means only that it is a pointer: int
*p;
(^) Don’t be confused with the dereferencing operator, which
is also written with an asterisk (*). They are simply two different tasks represented with the same sign int a = 100, b = 88, c = 8; int *p1 = &a, *p2, *p3 = &c; p2 = &b; // p2 points to b p2 = p1; // p2 points to a b = *p3; //assign c to b *p2 = *p3; //assign c to a cout << a << b << c;
Array Name is a pointer constant
#include
int main (){ int a[5]; cout << "Address of a[0]: " << &a[0] << endl << "Name as pointer: " << a << endl; }
Result : Address of a[0]: 0x0065FDE Name as pointer: 0x0065FDE
Dereferencing An Array Name
*#include
a[4] 22
a[0]
a[2]
a[1]
a[3]
a
a
This element is called a[0] or *a