Thread: Help with void pointer

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Help with void pointer

    Hi,

    As part of my ongoing c programming education, I have written a program to use void pointers in a function, however, I am experiencing a strange issue for which I would appreciate some assistance...


    Code:
    #include <stdio.h>
    
    #define  MAX_NUMBERS 10
    
    size_t size(void *object);
    
    int main(void) {
    
        int numbers[MAX_NUMBERS] = { 0,1,2,3,4,5,6,7,8,9 };
    
        printf("sizeof() = %d\n",sizeof(numbers));
        printf("size()   = %d\n",size(numbers));
    
        return 0;
    
    }
    
    
    size_t size(void *object) {
        return sizeof(object);
    }
    When I run the program I get the following output:

    Code:
    sizeof() = 40
    size()   = 4
    Now I think that the result 4 is the size of the pointer, so I'm confussed as why it doesn't give me the same result as 40.

    I'm sure i've missed something real simple

    Thanks

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void pointer
    By Sylar Persie in forum C Programming
    Replies: 4
    Last Post: 06-16-2012, 01:42 AM
  2. Casting to pointer to pointer to void
    By Sharke in forum C Programming
    Replies: 13
    Last Post: 05-12-2009, 08:40 PM
  3. Replies: 4
    Last Post: 08-27-2007, 11:51 PM
  4. Void Pointer and Pointer to Void
    By vb.bajpai in forum C Programming
    Replies: 13
    Last Post: 06-14-2007, 06:17 PM
  5. Dereference pointer to void pointer to member
    By phil in forum C Programming
    Replies: 5
    Last Post: 04-20-2005, 11:54 AM