Pointer in C | Detail Explanation

Pointer
Pointer in C

Through this article we will be going to discuss about Pointer in C in which following points are included

  1. Pointer in C
  2. Need of Pointer in C
  3. How to Initialise a Pointer ?
  4. How to declare a Pointer in C ?

Pointer in C:

A pointer is a special variable that is used to store the address of a few different variable. A pointer may be used to save the deal with of a single variable, array, structure, union, or even a pointer.

Need of Pointer in C:

Using Pointers allows us to –
- Achieve name by way of reference (i.E write functions which change their parameters)
- Handle arrays efficaciously.
- Handle structures (Record) efficiently.
- Create related lists, trees, graphs and so forth.
- Put records onto the heap.
- Create tables of features for dealing with windows occasions, alerts and so forth.
- Already been the use of pointers with scanf()
- Care have to be taken whilst the use of suggestions due to the fact there aren't any safety features.

How to Declare a Pointer Variable in C:

In C every variable must have be declare for its type variable contain address that belongs to separate data type the declaration of pointer variable take following form.

datatype *variable name;

This tells the compiler three thing about the variable of pointer which is listed below..
  1. The asterisk (*) tells that the variable pt_name is variable name is a pointer variable.
  2. Variable needs the memory loctaion.
  3. Variable name points to a variable of type datatype.

Example:-

int main()
{
int *p;
char *a;
float *x;
}

Here 'p' is a integer type pointer variable that holds only address of integer type variable only, and 'a' is character type pointer variable that holds the address of character variable only, and 'x' is another float type pointer variable that hold the address of float variable only.

How to initialise Pointer in C:

The process of assigning the address of variable to a pointer variable is know as initialisation of pointer in C, but the variable must be declare before the initialization take place.

Example:-

int main
{
int quantity;
int *p;
p=&quantity;
}
Here we can observe that quantity must be declare before the initialisation take place.

Conclusion:

In this article we have learned about, Pointer in C, Need of Pointer in C, How to Initialise a Pointer ?, How to declare a Pointer in C ?, in detail in further article we will cover remaining portion pointer, so , if you have any queries in this topic 
then feel free comment below.

Post a Comment (0)
Previous Post Next Post