Pointers Brief Overview
To go through the following chapters, I suggest briefly repeating the pointers in the C programming language.
Note
If you are not familiar with the basic skills of working with the C programming language, we recommend taking our basic C programming language course: C Basic
Dereferencing Operator
A pointer is a variable that contains the address of another object.
Dereference operator "*" returns the value stored at the address.
Declaring and initializing a pointer looks like this:
int* pName = NULL;
main.c
12345678#include <stdio.h> int main() { int* pName = NULL; printf("%p\n", pName); // `%p` is a specifier for a pointer return 0; }
Referencing Operator &
The "&" operator returns the address of an object:
main.c
12345678#include <stdio.h> int main() { int variable; printf("%p\n", &variable); return 0; }
A variable of pointer type is used to store the address, which is returned by the & operator.
int variable;
int* pVariable;
pVariable = &variable;
To "unpack" the contents at the specified address, you must use the * operator on a variable of type pointer.
main.c
12345678910#include <stdio.h> int main() { int variable = 1024; int* pVariable = &variable; printf("Address: %p\n", pVariable); // `%p` specifier for a pointer printf("Returned value by address: %d\n", *(pVariable)); // using `*` to pointer return 0; }
Swipe to start coding
- Declare and initialize any variable with any value;
- Declare a pointer to the same data type as your variable;
- Assign the address of a variable to a pointer;
- Display an address of your variable;
- Display the value of the variable by the pointer.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 4.17
Pointers Brief Overview
Veeg om het menu te tonen
To go through the following chapters, I suggest briefly repeating the pointers in the C programming language.
Note
If you are not familiar with the basic skills of working with the C programming language, we recommend taking our basic C programming language course: C Basic
Dereferencing Operator
A pointer is a variable that contains the address of another object.
Dereference operator "*" returns the value stored at the address.
Declaring and initializing a pointer looks like this:
int* pName = NULL;
main.c
12345678#include <stdio.h> int main() { int* pName = NULL; printf("%p\n", pName); // `%p` is a specifier for a pointer return 0; }
Referencing Operator &
The "&" operator returns the address of an object:
main.c
12345678#include <stdio.h> int main() { int variable; printf("%p\n", &variable); return 0; }
A variable of pointer type is used to store the address, which is returned by the & operator.
int variable;
int* pVariable;
pVariable = &variable;
To "unpack" the contents at the specified address, you must use the * operator on a variable of type pointer.
main.c
12345678910#include <stdio.h> int main() { int variable = 1024; int* pVariable = &variable; printf("Address: %p\n", pVariable); // `%p` specifier for a pointer printf("Returned value by address: %d\n", *(pVariable)); // using `*` to pointer return 0; }
Swipe to start coding
- Declare and initialize any variable with any value;
- Declare a pointer to the same data type as your variable;
- Assign the address of a variable to a pointer;
- Display an address of your variable;
- Display the value of the variable by the pointer.
Oplossing
Bedankt voor je feedback!
Awesome!
Completion rate improved to 4.17single