










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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to pointers in c programming, explaining how to declare pointers, get the address of a variable, and dereference a pointer. Pointers are powerful tools that provide faster access and are used in various ways, including simulating call-by-reference, accessing array information, and dynamic memory allocation.
Typology: Slides
1 / 18
This page cannot be seen from the preview
Don't miss anything!
Pointers
Pointers and arrays
Pointers and functions
Pointers
C uses pointers in three different ways
relationship with arrays and strings)
Data structures that can grow or shrink
int x = 10;
printf("Address of x = %p\n", &x);
Output:
Address of x = 0040FE
%p outputs the memory location as a hexadecimal integer
x
Location Address of x
int *myPtr ;
Declaring pointers
int *ptr1 , *ptr2 , *ptr3 ;
Declaring pointers
*int ptr , x , a [ 10 ] ;
Declaring Pointers
Getting address of a variable
xPtr = &x;
xPtr gets address of x
xPtr “points to” x
xPtr
x
5
xPtr
500000 600000
x
600000 5
Address of x
is value of
xPtr
Dereferencing Operator *
*ptr is read as
“The value of whatever ptr points to”
*z = xPtr + 2 ;
Dereferencing a pointer
Accessing the variable
pointed to by a pointer