Pointers is one of the most powerful features available in C Programming Language. A pointer is a special type of variable that refers to the address of other data objects or variables.
Variable can be of any data type i.e int, float, char, double, short, etc. C Pointer is used for dynamic memory allocation.
Syntax to Declare C Pointer Variable:
1 |
<data_type> *pointer_name; |
data_type specifies the type of pointer, then an asterisk (*) followed by the pointer name.
Example:
1 |
int *ptr; |
Example Program to Demonstrate Pointer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <stdio.h> int main() { int *ptr; int var1; var1 = 20; /* address of var1 is assigned to ptr */ ptr = &var1; /* display var1's value using ptr variable */ printf("%d", *ptr); return 0; } |
Output:
1 |
20 |