×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# C FAQ

## Pointers

 What is the declaration int *((*(*p[5])()))[10]; ? by ankan faq205-924 Posted: 22 Jul 01 One reason why I wrote this FAQ is that I did not find one dealing with such a controversial (and sometimes confusing) topic as this in the forum. Another (perhaps the main reason!!) is that I had not written any FAQ yet .If you ever had difficulties dealing with pointers (you would have certainly had, if you are a C programmer) then go through this FAQ. Otherwise don't bother.In the following declarations, p is ...int *p;        pointer to intint *p[10];    array[10] of pointers to int (not same as a 2D array)int (*p)[10];  pointer to array[10] of intint *p();      function returning pointer to intint (*p)();    pointer to function returning intint *(*p)();   pointer to function returning pointer to intint (*p[])();  array[] of pointers to function returning intint (*(*p())[5])(); function returning pointer to array[5] of pointers to function returning intThe above become quite clear when we consider the precedence and associativity of operators:   () [] {left to right}   *     {right to left}As an example what is p in the declaration:int *((*(*p[5])()))[10];One nice and easy way to come to the correct conclusion is by assuming that you are the compiler and going through the following obvious steps. Obvious when you keep in mind the precedence and associativity of the operators at hand that is [], ( ), *.First we have p[5] which is obviously an array, so we havearray[5] ofNext is *p[5], which is a pointer, thusarray[5] of pointers to Then (*p[5])(), which represents a function, hencearray[5] of pointers to function returning Then *(*p[5])(), a pointer hencearray[5] of pointers to function returning pointer toNext consider ((*(*p[5])()))[10], which is an array, so we getarray[5] of pointers to function returning pointer to array[10] of(an extra pair of ( ) above is of no use although it does no harm)Then comes *((*(*p[5])()))[10], which is a pointer, so we getarray[5] of pointers to function returning pointer to array[10] of pointers toLastly, the type which is int in this case which ultimately leads us toarray[5] of pointers to function returning pointer to array[10] of pointers to intWhen you are writing code all you have to do is to follow the reverse of the above steps, which is fairly easy.Such a complicated (?? if you have gone through the above, it should seem too simple now) pointer/array/function/etc is seldom used, I think.And a nicer and more foolproof way to use such a thing is by using typedef. But that's another story ... Bye.Ankan. Back to C FAQ Index Back to C Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!