| 25 | | ... |
| 26 | | }}} |
| | 23 | |
| | 24 | /* Wrong way: */ |
| | 25 | long *pTab[10]; // It creates an array with 10 pointers to the type long |
| | 26 | /* Easy-to-understand way: */ |
| | 27 | long (*pTab)[10]; // It creates a pointer to an array with 10 elements in type long |
| | 28 | }}} |
| | 29 | |
| | 30 | Note that using this way, not only your code is better to read but also a lot less error-prone specially for you, and for who needs to modify it, so that the program will do something different at what you are waiting to do, or that who reads it will think that it does something when is doing another thing. |
| | 31 | |
| | 32 | '''Tip''': Apart of that is more easy to read and less error-prone the method of using parentheses, in order to made your code clear and/or if you don't know the order of on which order the things are called in a line, use parentheses. |
| 293 | | |
| 294 | | *(array_p + 1) /* Equivalent */ |
| 295 | | (*array_p + 1 ) /* Not Equivalent */ |
| | 301 | *(array_p + 1) // Equivalent |
| | 302 | (*array_p + 1 ) // Not Equivalent |
| | 303 | |
| | 304 | /* All these methods are equivalent: */ |
| | 305 | &a[i] , a+i , pa+i , &(pa[i]) // Pointers to the 'i' element of an array |
| | 306 | a[i] , *(a+i) , *(pa+i) , pa[i] // In the same method way, the 'i' element of an array (no-pointer) |