R
Raman
Hi All,
As per my understanding, malloc and calloc differs in the way they
allocate memory( malloc give a contigous block, But calloc may give
Non-contigous block as well).
Now consider this program.
int main()
{
char *p;
p=(char *) calloc(10,sizeof(char));
*(p+2)='O';
*(p+8)='S';
return (0);
}
suppose calloc returns space in two blocks( 5 byte at address
starting at1000 and rest 5 bytes at 2000).
Now (p+2) is 1002.
(p+8) is 1008
But 1008 is not the part of space allocated to p.
I dont know my interpertation of non-contigous blocks is right or not.
Please help.
Thanks
Raman Chalotra
As per my understanding, malloc and calloc differs in the way they
allocate memory( malloc give a contigous block, But calloc may give
Non-contigous block as well).
Now consider this program.
int main()
{
char *p;
p=(char *) calloc(10,sizeof(char));
*(p+2)='O';
*(p+8)='S';
return (0);
}
suppose calloc returns space in two blocks( 5 byte at address
starting at1000 and rest 5 bytes at 2000).
Now (p+2) is 1002.
(p+8) is 1008
But 1008 is not the part of space allocated to p.
I dont know my interpertation of non-contigous blocks is right or not.
Please help.
Thanks
Raman Chalotra