Pointer ( * and & )
Try it yourself →Holds the address of a variable.
Syntax
type *p = &variable;
Description
& gives the ADDRESS of a variable; * accesses the VALUE at that address. Pointers are C's most powerful and demanding feature.
Example
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
printf("%d\n", *p);
*p = 20;
printf("%d\n", x);
return 0;
}Expected output
10 20
When to use?
Passing data to a function by reference, dynamic memory, arrays.
Common mistakes
- ⚠️ & gets the address, * accesses the value — don't mix them up.
- ⚠️ Reading an uninitialized pointer (*p) causes a crash.