Introduction
Learn more about pointers and how to use them in your programs.
We'll cover the following
Understanding pointers
A pointer is a special kind of variable that stores the address in the memory of another variable and can manipulate that variable.
Declaring pointers
To declare a variable as a pointer, its identifier must be preceded by an asterisk *
. When you use *
before an identifier, it indicates that the declared variable is a pointer.
Next, you need to assign the address of a variable to the pointer before you can actually use it.
int *p1; // Declare a pointer
int i = 5; // Declare a variable
p1 = &i; // Assign address to a pointer
printf("%d", *p1); //print the pointer's value
To better understand the concept of pointers, let’s look at an illustration.
Get hands-on with 1400+ tech skills courses.