0

When I run this program, output is 4 bytes. ( I use a 64 bit compiler)

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

int main(void) {
    int *b;
    b=(int*)malloc(10*sizeof(int));
    printf("%d",sizeof(b));
    return 0;
}

But shouldn't the output be 40 bytes as I am dynamically allocating 40 bytes of space for 'b'?

1 Answers1

0

No; it should be the same as printf("%zu", sizeof(int *));, which on your implementation is 4, no matter what value you assign to b, since b has type int *, not int [10].

HolyBlackCat
  • 63,700
  • 7
  • 105
  • 170
Jens
  • 65,924
  • 14
  • 115
  • 171