|
-
April 27th, 2004, 10:12 AM
#4
Check out this thread. The meat of what you're looking for doesn't start until after the first few posts. But read the entire thread. This will give you half of the information you desire.
Guysl is correct. 'blah' is a pointer to an array of 10 characters. Look at this valid code:
Code:
#include <stdio.h>
int main()
{
int array[2][10] =
{{0,1,2,3,4,5,6,7,8,9},
{10,11,12,13,14,15,16,17,18,19}};
int (*array_ptr)[10] = &array[0];
printf("%d\n", (*array_ptr)[5]);
++array_ptr;
printf("%d\n", (*array_ptr)[5]);
return 0;
}
This is where you might really choose to use a syntax like 'type (*)[size]'. array_ptr is a pointer to an array. In order to access an element of the array, you must first dereference the array {'(*array_ptr)'} and then indicate an element {'[5]'}. Compile and run the code. Notice how in the first printf() call, array_ptr points to the first array {indicated by the output '5'}, and in the second printf() call, array_ptr points to the second array {indicated by the output '15'}. All that was needed to move the array reference was to increment 'array_ptr' by 1.
All that being said, this usage is rather uncommon and can easily lead to a lot of confusion. I would strongly discourage using this programming style unless there was no clearer way to solve your problem.
Hope this helps!
- Kevin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|