Thread: sizeof pointer-to-array -- &array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    sizeof pointer-to-array -- &array

    Hello everyone. I'm trying to find out the size of some expressions.

    Code:
    #include <stdio.h>
    
    int main(void){
        char   a [100] = {0};
        char (*p)[100] = &a;
    
        printf("%d\n", sizeof  a[0]);
        printf("%d\n", sizeof &a[0]);
        printf("%d\n", sizeof  a);
        printf("%d\n", sizeof  p);
        printf("%d\n", sizeof &a);
    
        return 0;
    }
    The 1st expression is type char and I get 1

    The 2nd is type char* (pointer-to-char), and I get 4--because of beeing on a 32 bits plataform, right?

    The 3rd one is type char[100] (array-of-100-char), and I get 100

    The 4th is type char(*)[100] (pointer-to-aray-of-100-char), and I get 4.

    The last one is also type char(*)[100] (pointer-to-array-of-100-chars), but I get 100, shouldn't I get 4?

    I've tested this progrman on an MS and on a Borland compiler. Both gave me the same result.

    I've looked in various books and the standard and I think I should be getting 4, not 100.

    What do you think?

    Thanks.

    Joey.
    Last edited by josemariasola; 07-15-2006 at 02:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. pointer to multidimensional array
    By Bigbio2002 in forum C++ Programming
    Replies: 4
    Last Post: 02-05-2006, 10:29 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM