what is the type "blah" when declared:
thanks.Code:char (*blah)[10];
Printable View
what is the type "blah" when declared:
thanks.Code:char (*blah)[10];
its a pointer to a fixed-size block of 10 characters.
as opposed to an array of 10 character pointers. interesting, thanks for the reply.Quote:
Originally posted by Guysl
its a pointer to a fixed-size block of 10 characters.
so whats the difference between:
andCode:char *p;
they are both pointers to one character, right? can they be used interchangeably? well, no they can't, but more discussion plz...=)Code:char (*p)[1];
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:
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.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;
}
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
yeah, i totally agree with you. unfortunately, i think it has to be this way. these types of arrays are used in Pro*C code to read many rows of a column (chars[n]) into an array in one fell swoop.Quote:
Originally posted by KevinHall
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.
anyways, great post thanks for your help.
No problem!