For me pointers are the only reason I love C Programming. It broadens the concept of programming. And as a programmer I use to do programming through pointers mainly, as it eliminates many limitations of the program smartly. We can’t achieve swapping of two numbers without pointers when we are using a function call because every time actual arguments gets copied and being pass to the function, and becomes the formal arguments of that function. Any change in formal argument won’t make the actual arguments change. So cleverly we can pass the addresses as the formal arguments of the variables and can change the values using addresses.
Look at the Program Carefully ►►
void swap(int *,int *); //Function Prototype Declaration
printf(“Enter the values of A and B\n”);
swap(&a,&b); //Function Call
printf(“After Swapping … \n a=%d \t b=%d”,a,b);
void swap(int *x,int *y) //Function Definition
What happen is, we simply pass the addresses of variables(a,b) through ‘address of operator’ (&,ampersand) and receive it in the function using pointers. Now we know the addresses are the place where the values actually stored so we simply inter-change the values on that addresses. And addresses are the unique for every variable so wherever in the program we done something on the addresses, we can see the change anywhere in the program.