Pointer is a variable that stores memory addresses. Unlike normal variables it does not store user given or processed value, instead it stores valid computer memory address.
Pointer allows various magical things to be performed in C.
- Pointers are more efficient in handling arrays and structures.
- Pointers are used to return multiple values from a function.
- Pointer allows dynamic memory allocation and deallocation (creation and deletion of variables at runtime) in C. Which undoubtedly is the biggest advantage of pointers.
- Pointer allows to refer and pass a function as a parameter to functions.
and many more…
For beginners pointers can be a bad dream if not practiced well. However, once mastered you can do anything you want to do in C programming language.
In this exercise I will cover most of the pointer related topics from a beginner level. Always feel free to drop your queries and suggestion down below in the comments section.
Required knowledge
Pointers, Pointer Arithmetic, Pointer to Pointer, Pointer and Arrays, Function Pointer
Please go through above tutorials to get a good grasp of following examples.
List of pointer programming exercises
- Write a C program to create, initialize and use pointers.
- Write a C program to add two numbers using pointers.
- Write a C program to swap two numbers using pointers.
- Write a C program to input and print array elements using pointer.
- Write a C program to copy one array to another using pointers.
- Write a C program to swap two arrays using pointers.
- Write a C program to reverse an array using pointers.
- Write a C program to search an element in array using pointers.
- Write a C program to access two dimensional array using pointers.
- Write a C program to add two matrix using pointers.
- Write a C program to multiply two matrix using pointers.
- Write a C program to find length of string using pointers.
- Write a C program to copy one string to another using pointers.
- Write a C program to concatenate two strings using pointers.
- Write a C program to compare two strings using pointers.
- Write a C program to find reverse of a string using pointers.
- Write a C program to sort array using pointers.
- Write a C program to return multiple value from function using pointers.