hi,i would like to know how to calculate the size of a dynamic arraycreated using a dereference declaration like int *numbers andallocating via malloc or calloc: numbers=(int*)malloc(sizeof(int)*10);using sizeof(numbers) will return the pointers size...is there a possibility?D@nny--life already is expensive, so why waste money on expensivesoftware. 解决方案Yes. You know the size when you allocate it. Just retainthat value (i.e. store it in a ''size_t'' object).int *numbers = 0;size_t sz = 10 * sizeof *numbers;if(numbers = malloc(sz)){printf("%lu bytes allocated.\n", (unsigned long)sz);/* do stuff */free(numbers);}-MikeObviously, there is. If you can figure out how much space to ask mallocfor, you already know the answer.Not in standard C. You''ll have to use implementation-specific tricks.But since you know the size when you allocate the memory, why not simplykeep track of it?--/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\\-------------------------------------------------------- rules! --------/"To know me IS to love me."- JIPsoft 这篇关于sizeof动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 06:15