Quiz Entry - updated: 2026.07.10
How do you dereference a pointer to get/set the value it points to?
Put * in front of a pointer: *p reads the value it points at, and *p = … writes through it to the original variable.
int x = 42;
int *p = &x;
// READ through pointer
// value = 42
int value = *p;
// WRITE through pointer
// x is now 100
*p = 100;
Dereferencing NULL crashes:
int *p = NULL;
// SEGFAULT! Dereferencing null pointer
*p = 5;
Always check before dereferencing:
if (p != NULL) {
*p = 5;
}
// Or shorter:
if (p) {
*p = 5;
}
Double dereference (pointer to pointer):
int x = 42;
int *p = &x;
int **pp = &p;
// x is now 100
**pp = 100;