What are pointers and its advantages | Allinonetuts

What are pointers and its advantages? Explaining with the Example.

Pointers :

A pointer is a variable that contains an address which is a location of another variable in memory. Since a pointer is a variable, its value is also stored in the memory in another location. Suppose we assign the address of quantity to a variable p. The link between the variables p and quantity can be visualized as shown in the figure.

pointers as variable | Allinonetuts
The address of p is 5048. Since the value of variable p is the address of the variable quantity, we may access the value of a quantity by using the value of p and therefore, we say that the variable p points to the variable quantity. Thus, p gets the name ‘pointer’.

Advantages :

  1. Pointers reduce the length and complexity of a program.
  2. They increase execution speed.
  3. A pointer enables us to access a variable that is defined outside the function.
  4. Pointers are more efficient in handling the data tables.
  5. The use of a pointer array of character strings results in saving of data storage space in memory.

/ * Accessing variables using Pointers*/ :

main ()
{
int x, y;
int *ptr;
x = 10;
ptr = &x
y = * ptr;
printf ( “value of x is % d \n \n”, x);
printf ( “%d is stored at addr % u \ n” , x, &x);
printf ( “%d is stored at addr % u \n”, * &x, &x);
printf ( “%d is stored at addr % u \n’\ y, &*ptr);
printf ( “%d is stored at addr % u \n”, ptr, &ptr);
}
Hello Viewers,
welcome to the Allinonetuts a Technical tutorial and Programming Blog Maintained by Vikas Kardam, a Web Developer and Blogger From Delhi, India.
What are pointers and its advantages in C Programming? Explaining with example. was last modified: July 1st, 2017 by Vikas Kardam
Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

Leave a Reply

Your email address will not be published. Required fields are marked *