Search

Monday, January 27, 2014
0 comments

Introducation to Pointer DataStructure, C Programming

2:41 AMMonday, January 27, 2014
 Pointer is a special type of variable that is used to store the memory address of another variable of free memory requested by the programmer or user during the execution of  the program. To understand dynamic data structures understanding pointer is definitely must. In simple words pointer is a variable that stores memory address whereas simple variables store data.

              For example, when variable is declared the memory is allocated to that variable by the compiler during the compilation of the program. Once memory is allocated the data can be stored in that memory location. The data is referred by the name of the variable. If the address of that variable is to be stored then the pointer variable is necessary. Consider the declaration statement of “C” language: int age;

            Assuming that during compilation memory address allocated variable age is 1000, and the address 1000 is to be stored in another variable that variable should be of the type pointer.
           In case of ‘C’ language the pointer variables are simply declared by means of prefixing an asterisk (*) to the variable name in a normal declaration statement. For example, int *page; declares a pointer variable page of the type int. Now page can be used to store the address of a simple integer variable. i.e. page = &age.
            When a pointer variable is declared, the memory is not allocated to such variable during the compilation. So it can point to any already allocated address of variable or an address of requested free memory. The type of free memory or variable should match with the type of pointer variable. Pointer variables are advantageous when they are used for dynamic memory allocation and function call by reference.

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top