|
-
April 26th, 2004, 05:57 PM
#1
what is the type of char (*blah)[10]
what is the type "blah" when declared:
thanks.
-
April 26th, 2004, 06:16 PM
#2
its a pointer to a fixed-size block of 10 characters.
**** **** **** **** **/**
-
April 27th, 2004, 09:41 AM
#3
Originally posted by Guysl
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.
so whats the difference between:
and
they are both pointers to one character, right? can they be used interchangeably? well, no they can't, but more discussion plz...=)
-
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
-
April 27th, 2004, 10:29 AM
#5
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.
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.
anyways, great post thanks for your help.
-
April 27th, 2004, 11:28 AM
#6
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
|