Using sizeof with a dynamically allocated array

Posted by robUK on Stack Overflow See other posts from Stack Overflow or by robUK
Published on 2010-04-28T16:51:34Z Indexed on 2010/04/28 17:03 UTC
Read the original article Hit count: 145

Filed under:
|

Hello,

gcc 4.4.1 c89

I have the following code snippet:

#include <stdlib.h>
#include <stdio.h>

 char *buffer = malloc(10240);
 /* Check for memory error */
 if(!buffer)
 {
    fprintf(stderr, "Memory error\n");
    return 1;
 }
 printf("sizeof(buffer) [ %d ]\n", sizeof(buffer));

However, the sizeof(buffer) always prints 4. I know that a char* is only 4 bytes. However, I have allocated the memory for 10kb. So shouldn't the size be 10240? I am wondering am I thinking right here?

Many thanks for any suggestions,

© Stack Overflow or respective owner

Related posts about c

    Related posts about sizeof