+ 1

sizeof operator in malloced memory(C language)

How can I get no of total bytes in a malloced memory by using sizeof operator? as int* a=(int*) malloc(10*sizeof(int)) how can I get the total no of bytes used by the array by using sizeof operator?

30th Oct 2018, 6:32 PM
Jyotiprakash Das Karmakar
Jyotiprakash Das Karmakar - avatar
2 Respostas
+ 2
Jyotiprakash Das Karmakar, IMO it's not possible... that's the reason we should keep track of allocated members count... in your code , a is pointer and same would give you size of pointer... *a is first element and same would give you size of int type.... also you can't be sure that howmnay elements are present in array as you can access next unallocated elements with few compilers....sm1 plz correct me if I m wrong
30th Oct 2018, 6:45 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
Thanks...
30th Oct 2018, 7:20 PM
Jyotiprakash Das Karmakar
Jyotiprakash Das Karmakar - avatar