+ 7
What does the c stand for in calloc, the C language memory allocation function?
malloc stands for memory allocation. Does calloc stand for 'cleared' or 'counted' memory allocation? I Googled this and it seems even Brian Kernighan is not sure. So, no high hopes of anyone here coming up with an answer. I am also prepared to receive responses like 'Does it even matter? Just use the function and don't ask trivial questions.'
14 Réponses
+ 7
sree harsha how do you know that it stands for contiguous? I am saying because the original documentation for stdlib.h is quite poor apparently.
+ 5
Yup I know what it does. Just don't know what the C stands for 😢. Does anyone have Dennis Ritchie's phone number?
+ 5
That's a good point Schindlabua, a bit like csh (C-shell) is due to the C language. I guess the mystery continues....
+ 4
Thus if you reset c to zero you destroy memory blocks upon calloc or clean the fields as in to reset an array or series of fields in a given structure.
+ 3
calloc sets allocated memory to zero.
+ 3
Since there's nothing officially documented with regards to what the first c stands for in calloc, there's no right answer. When SL was working on the malloc/calloc lessons, we once thought that it stood for 'contiguous'. Although it could not be confirmed nor invalidated, both malloc and calloc allocates contiguous memory, so 'contiguous' really isn't that good of a contender for the spot. 'clear' or 'count' does have a better representation of calloc.
+ 3
Hatsy Rei if c is setting it to zero and zero being a digit would this not express a counter verses a string ~ just asking
+ 3
Hatsy Rei Yes calloc c being counter as it resets to zero not as to clear memory as per c
+ 3
From what I've read, calloc as 'count' allocation draws a distinction between calloc and malloc in the sense that malloc allocates memory in terms of specified bytes, and calloc in terms of the 'count' of memory blocks.
+ 3
Sonic I bet it's "because www.programiz.com says so". :> Tbh, I was also mislead some time ago.
+ 2
I have wondered about that too. I was thinking the C stands for C, the language.
Like some programmer somwhere was learning this new language called C where you have to allocate memory with malloc and they thought they had a better idea and so they made a "C allocation function" that takes 2 arguments instead of 1 and zeroes the memory. And somehow it ended up inside stdlib at some point.
But I'm also just speculating of course.
+ 2
BroFarOps©®️™️🐱 Are you referring to the unsuitability of 'count' to represent c in calloc or... ?
+ 2
calloc stands for contiguous allocation
All the values of variable declared in calloc are zeros
syntax:
pointer = calloc(no of elements, sizeof(datatype));