C Programming - Pointers

Pointers Varieties

(1) int *p; // p is a pointer to an integer quantity

(2) int *p[10]; // p is a 10-element array of pointers to integer quantities

(3) int (*p)[10]; // p is a pointer to a 10-element integer array

(4) int *p(void); // p is a function that returns a pointer to an integer quantity

(5) int p(char *a); // p is a function that accepts an argument which is a pointer to a character returns an // integer quantity

(6) int *p(char *a); // p is a function that accepts an argument which is a pointer to a character returns a // pointer to an integer quantity

(7) int (*p)(char *a); // p is pointer to a function that accepts an argument which is a pointer to a character // returns an integer quantity

(8) int (*p(char *a))[10]; // p is a function that accepts an argument which is a pointer to a character returns a // pointer to a 10-element integer array

(9) int p(char (*a)[]); // p is a function that accepts an argument which is a pointer to a character array returns // an integer quantity

(10) int p(char *a[]); // p is a function that accepts an argument which is a array of pointers to characters // returns an integer quantity

(11) int *p(char a[]); // p is a function that accepts an argument which is a character array returns a pointer to // to an integer quantity

(12) int *p(char (*a)[]); // p is a function that accepts an argument which is a pointer to a character array returns a // pointer to an integer quantity

(13) int *p(char *a[]); // p is a function that accepts an argument which is an array of pointers to characters // returns a pointer to an integer quantity

(14) int (*p)(char (*a)[]); // p is pointer to a function that accepts an argument which is a pointer to a character array // returns an integer quantity

(15) int *(*p)(char (*a)[]); // p is pointer to a function that accepts an argument which is a pointer to a character array // returns a pointer to an integer quantity

(16) int *(*p)(char *a[]); // p is pointer to a function that accepts an argument which is a array of pointers to // characters returns a pointer to an integer quantity

(17) int (*p[10])(void); // p is 10-element array of pointers to functions; each function returns an integer quantity

(18) int (*p[10])(char a); // p is 10-element array of pointers to functions; each function accepts an argument which is // a character and returns an integer quantity

(19) int *(*p[10])(char a); // p is 10-element array of pointers to functions; each function accepts an argument which is // a character and returns a pointer to an integer quantity


(20) int *(*p[10])(char *a); // p is 10-element array of pointers to functions; each function accepts an argument which is // a pointer to a character and returns a pointer to an integer quantity


Pointer-to-Pointer and Reference-to-Pointer

This article explains the reason behind using pointer-to-pointer and reference-to-pointer to modify a pointer passed to a function, to better understand their usage.

When we use "pass by pointer" to pass a pointer to a function, only a copy of the pointer is passed to the function. We can say "pass by pointer" is passing a pointer using "pass by value." In most cases, this does not present a problem. But, a problem arises when you modify the pointer inside the function. Instead of modifying the variable, it points to it by de-referencing. When you modify the pointer, you are only modifying a copy of the pointer and the original pointer remains unmodified.

Please look at the "Pointer-to-Pointer and Reference-to-Pointer" for the complete example.

All the Best !!!


Links
www.c4swimmers.net

Pointer-to-Pointer and Reference-to-Pointer -http://www.codeguru.com/cpp/cpp/cpp_mfc/pointers/article.php/c4089/

http://www.codeproject.com/KB/cpp/PtrToPtr.aspx