Home | » | C Programming | » | C Pointers |
Only the C Language supports pointers and they play an important role in it. Pointers are very simple to use, provided the basic concept is understood properly. Mainly pointers are used in C Program to acquire as much as stroage space to store more values at a time and at the same time allow the program to deallocate the storage, which is no more required in the program. Learning of pointer may be difficult, but not too difficult. It looks difficult because it is new topic and pointers are not used in the basic learning languages like Basic, Cobol, Fortran etc.
Contents
- What is Pointer ?
- Use of Pointer or Advantages of Pointer
- Declaring a Pointer Variable (Initialization of Pointer)
- Pointer Variables
- Pointer Program Using Function (Pass By Reference)
Definition :
Pointers are memorey addresses variable i.e the variables, which have addresses of the variable having some value, stored in the memory. Further we can say pointers are directly linked to the memory address. Actually pointer is a variable having address of another variable and not the value. For example, suppose q is an integer variable and this variable have value 250 stroed in the memory.
It is represented as :
Variable name | Memory value | Memory address | Memory variable |
q | 250 | 5000 | p (pointer) |
Use of Pointer or Advantages of Pointer :
Pointers are used to direct link the memory address. Now question arises, Why pointers are required.
To solve this question some reasons for the use of the pointer are discussed as follows:
A pointer enables the varible, which is used outside the function or used in the another Sub-program.
Pointers increase the execution speed of the C-Program and are more efficient.
Pointers reduces the length and complexity of the program.
Pointers accesses the memory elements very easily.
Pointers are more efficient in handling the date table i.e. two-dimensional way.
Use of the pointer to the character array or to the string save the storage space in the memory.
Pointers have direct link with structure and union.
By using pointer, we can declare lesser number of variables in memory.
Pointers help to return more than one value from the function sub-program
By using pointers, function arguments can be passed to the functions.
Pointers saves the memory space. This can be done by using the dynamic memory allocation technique.
Pointers are also very useful to handle files.
Pointers are very useful in data structure manipulation.
Declaring a Pointer Variable (Initialization of Pointer) :
Declaration of pointer variable is similar to the declaration of a common variable. A Pointer variable should be declared before they are used.
When we want to use pointer variable, then these should be declared in data-type statement used in the beginning of main program. The general syntax used for the declaration of pointer (memory variable) is as:
Where data-type may be integer (int), real (float), character (char) or double. Also here * (asteric sign) means it is pointer operator and pointer variable is any variable linked with '*' sign . The symbol * is called indirection operator. Some valid pointer declaration statement are as follows:
float *y;
char *c;
For example, suppose if p is a pointer variable, which gives the address of the variable, then we can use the above statement as:
int *p, q=250;
p = &q; /* This is initialization of Pointer*/
printf("\n %d is stored at address %u",q,p);
Here the result be as :
250 is stored at address 5000
Note that the format code in the control string of printf() statement be %u because addresses are always unsigned integer.
Pointer Variables
|
Pointer Program Using Function (Pass By Reference)
3 comments
Click here for commentsSaga enterprises is 8 years old detective agency in pune with a vision to cater the detection and surveillance services. Saga enterprises is an authorized and well-known detective agency in Pune. To support for righteousness and to fight against exploitation is the major emphasis of ‘Saga Enterprises’. We offer our services throughout India though we officially located in Pune.
Replycorporate investigation in pune
Matrimonial investigation in pune
personal investigation in pune
I found useful article in your blog.thank you
Replyvisit
web programming tutorial
welookups.com
ConversionConversion EmoticonEmoticon