Friday 12 December 2014

Pointer in C

Pointer in C are one of the amazing tools that can be used while programming. The are very useful in dynamic allocation and also they decrease the program execution time that is time required to run the program.

By the definition if we talk than :

A pointer is a variable whose value is the address of the another variable.


Declaring a pointer :



type *var-name ;


Here type is the base type of the pointer (it can be int,float,long,double,etc.) while "var-name" is the name of the variable. When asterisk(*) sign is added before the variable than that variable is known as pointer variable.

NOTE :- In case of multiplication asterisk(*) sign is placed after the variable while in case of pointer they are placed before the variable.



int *a; //pointer to an integer

double *df; //pointer to a double

char *ch; //pointer to a character



EXAMPLE :


#include&ltstdio.h&gt
int main()
{
int *point, c=98;
point = &c;   /* Ampersand(&) assigns the address of variable  to pointer variable.*/
printf("Value of pointer is : %d", *point);
printf("Address to which pointer points : %p",point);
}



VIDEO FROM OUR YOUTUBE CHANNEL :