A Little about the blog.....

This blog contains all the interview questions that i face during my interviews with various MNC's. I am trying to post the solutions for almost all the questions and i have covered few important topics which would be frequent topics in interviews. I hope the blog would be useful not only for the job aspirants but also to the one who tries to upgrade his/her knowledge in C and Embedded concepts......

please enter your mail address in the above mail address box to get the immediate updates of the new interview questions.....

Thursday, November 10, 2011

Different types of Pointers

The concept of pointers is the Beauty behind the use of C language. We know that, in general pointer refer to some address location in the memory.

There are different types of Pointers in C language that any C aspirant is ought to know about. let's have a brief glance about them.

1. pointer depending upon the type of the variable it is referring to.
ex: integer pointer, Character pointer, float pointer etc;

2. Dangling Pointer.
explanation: It is the pointer to a memory location where is varibale is stored
earlier but not present now ( destroyed or cleared or freed by the program).simply OBJECT DESTROYED BUT PATH PRESENT.

3. NULL Pointer.
explanation: To avoid the errors caused by the dangling pointer, the concept of a NULL POINTER is introduced. Whenever the NULL POINTER is dereferenced/freed, there is no scope for data corruption.
ex: #DEFINE NULL 0 //defining a null value
int *a; // defining a integer pointer
free(a); // the value at a is destroyed, hence a is a Dangling pointer
a=NULL; // now 'a' is a safe pointer

4. VOID Pointer.
explanation: also called as generic pointer. a void pointer can be of any type.
ex: *(int)p, *(float)p, *(char)p

5. CONSTANT POINTER.
explanation: the constant pointer's value cannot be changed once it is declared as CONSTANT.
ex: const int* const p= &a;

6. FUNCTION POINTER.

explanation: To store the address of a function,we need a function pointer.
ex: void main()
{void(*fp)();
fp= calling function name;
fp();
}

No comments:

Post a Comment