C Programming + Tutorials in C for Beginners

C Pointers

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.


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 nameMemory valueMemory addressMemory variable
q2505000p (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:

  1. A pointer enables the varible, which is used outside the function or used in the another Sub-program.

  2. Pointers increase the execution speed of the C-Program and are more efficient.

  3. Pointers reduces the length and complexity of the program.

  4. Pointers accesses the memory elements very easily.

  5. Pointers are more efficient in handling the date table i.e. two-dimensional way.

  6. Use of the pointer to the character array or to the string save the storage space in the memory.

  7. Pointers have direct link with structure and union.

  8. By using pointer, we can declare lesser number of variables in memory.

  9. Pointers help to return more than one value from the function sub-program

  10. By using pointers, function arguments can be passed to the functions.

  11. Pointers saves the memory space. This can be done by using the dynamic memory allocation technique.

  12. Pointers are also very useful to handle files.

  13. 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:

data-type *pointer-variable;

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:

int *p;
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

Simple Variable
Pointer variable
Pointer to Pointer
int a;
a = 10;
int *p;
p = &a;
int **t;
t = &p;

Pointer Program Using Function (Pass By Reference)

<< Previous Topic
Next Topic >>

Next Post »


Click here for comments
30 July 2018 at 04:01 ×

Saga 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.

corporate investigation in pune

Matrimonial investigation in pune

personal investigation in pune

17 August 2018 at 06:44 ×

I found useful article in your blog.thank you
web programming tutorial

25 August 2018 at 09:15 × This comment has been removed by the author.
28 August 2018 at 02:55 ×

I found best article.thank you for sharing useful info.
web programming tutorial

Thanks for your comment