CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2000
    Location
    austin
    Posts
    101

    what is the type of char (*blah)[10]

    what is the type "blah" when declared:
    Code:
    char (*blah)[10];
    thanks.

  2. #2
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    its a pointer to a fixed-size block of 10 characters.
    **** **** **** **** **/**

  3. #3
    Join Date
    Jun 2000
    Location
    austin
    Posts
    101
    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:

    Code:
    char *p;
    and
    Code:
    char (*p)[1];
    they are both pointers to one character, right? can they be used interchangeably? well, no they can't, but more discussion plz...=)

  4. #4
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    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

  5. #5
    Join Date
    Jun 2000
    Location
    austin
    Posts
    101
    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.

  6. #6
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    No problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured