Programming

Pointing to Pointer

It is rightly said that if someone masters pointers he has mastered half the C. Pointers  have always been a very difficult and confusing part in C. But the power they have in the coding arena is unparalleled. They form the basis of core programming .

Lets start with this topic of pointers. First and foremost its important to read and understand the declaration of pointers. So here we go,

  1. int a         // a is a variable to an integer.
  2. int *p      // p is a pointer to an integer.
  3. int **p    // p is a pointer to a pointer to an integer.
  4. int ***p  // p is a pointer to a pointer to a pointer to an integer.
  5. int a[5]   // a is one dimensional array of 5 integers.
  6. int *p[5]  // p is one dimensional array of 5 integer pointers.
  7. int (*p)[5] // p is a pointer to one dimensional array of 5 integers. OR p is  a pointer to 1 dimensional array holding base address of 2 dimensional array.
  8.  int (*p)[5][5] // p is a pointer to two dimensional array of 5X5 integers. OR p is  a pointer to two dimensional array holding base address of three dimensional array.
  9. int f() // f is a function which doesn’t take any parameter and returns an integer.
  10. int f(int) // f is a function which takes a integer parameter and returns a integer.
  11. int *f(int) // f is a function that takes an integer as a parameter and returns an integer pointer.
  12. int (*f)() // f is  a function pointer (OR a pointer to a function) that takes no argument and returns an integer.
  13. void (*f)() // f is  a function pointer (OR a pointer to a function) that takes no argument and returns nothing.
  14. int (*f)(int) // f is a function pointer (OR a pointer to a function) that takes integer parameter and returns an integer.
  15. int (*f[5]) (int) // f is one dimensional array of 5 function pointers that take integer parameter and return an integer.
  16. int (*f) (int*, int*) // f is function pointer (OR a pointer to a function) that takes two integer pointers (OR pointer to an integer) as arguments and returns an integer.
  17. char (*(*f())[3]) () // f is a function that takes no argument and returns a pointer to an array of 3 function pointers that take no argument but character.
  18. int (*(*f)())[5][4] // f is a function pointer that receives nothing and returns a pointer to a 2 dimensional array of 5X4 integers.
  19. char (*(*f[3])()) [20] // f is an array of 3 function pointers that receive nothing and return pointer to 1 dimensional array of 20 characters.
  20. float *(*(*(*f)())[10])() // f is function pointer that receives nothing and returns a pointer to an array of 10 function pointers that receive nothing and return float pointer.

If you master how to read and  interpret a statement containing pointer it makes the way further quite pleasant. So learn this tutorial and post your comments.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s