Hoping that you have an idea on functions and some basic terms of C including a brief idea on memory address here we are with Pointers.
Definition: Actually a POINTER is nothing but memory addresses. A POINTER is a variable that contains the memory location of another variable. Therefore, a pointer is a variable that represents the location of a data item, such as a variable or an array element.
Pointers are also variables and play a very important role in C programming language. They are used for several reasons, such as:
- Strings
- Dynamic memory allocation
- Sending function arguments by reference
- Building complicated data structures
- Pointing to functions
- Building special data structures (i.e. Tree, Tries, etc...)
And many more.
To clear your concepts you can follow Step 1: Visit this article to Clear your basic theory
Step 2: Visit this article to deep dive into the pointers
If you have enough time you can follow these videos sequentially to master Pointers.
1. Introduction to Pointers in C
2. Declaring and initializing Pointers
3. Pointer and function
4. Value of operators in Pointers
4. Value of operators in Pointers
5. Pointer Assignment
5. Returning Pointers
If you have seen all the above links and videos, then here you are with some applications on POINTERS which are divided in the easy and intermediate stage; hope you'll be able to solve these:
Problem Set: Level Basic
1. Sum of two numbers (Solution)
2. Swapping of two variables using and without using the third variable. (Solution)
3. Program to print vowels and consonants using a pointers (Solution)
4. Program to read array elements and print with address (Solution)
Problem Set: Level Intermediate
1. Swap two 1-D arrays.
2. Print ASCII values of string.
3. Linear search on an array.
4. Fill the question mark to get "void pointer" as an output?
#include<stdio.h>
int main()
{
char *ptr = "void pointer";
void *vptr;
vptr = &ptr;
printf("%s" , ?);
return 0;
}
5. Complete the function void update(int *a,int *b), which reads two integers as argument, and sets a with the sum of them, and b with the absolute difference of them:
a' = a+b
b' = |a-b|
[ sample input:
4
5
sample output:
9
1
]
6. Given an array of N elements. The task is to complete the function which returns if triplets exist in the array whose sum is 0. (hint: use of double pointers)
: ALL THE BEST :
Post a Comment