Re: malloc realloc and pointers
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Thu, 29 Nov 2007 21:27:44 -0600
On Thu, 29 Nov 2007 21:50:38 +0100 (CET), ravi <nospam@xxxxxxxxxxxxxx>
wrote in comp.lang.c:
Hi all,
I m relatively new to C. I have few queries related to malloc():
1. When we perform malloc(), the memory allocated dynamically comes from
the heap area of the process in concern. Well, we then say that the heap
has shrinked. my query is: Is it that the heap physically does not
shrink but the perticular nodes are marked 'ALLOCATED' and for
subsequent calls to malloc() the memory manager remembers them and does
not reference them?
2. With realloc(), if some pointer 'ptr' is pointing initially to a
perticular position in a buffer (char *buffer) then on performing a
realloc() on this buffer, what will be 'ptr' pointing to?
3. whats the maximum memory size that we can allocate dynamically by
calling malloc() ?
4. Is it valid in C to typecast a pointer? eg. code snippet... of
course int is 16 bit and long is 32 bit.
int *variable, value;
*((long*)variable)++ = value;
This is not legal C code. The cast generates an rvalue, and the post
increment operator cannot be applied to lvalues. You cannot assign to
the result of a cast.
*((long*)variable)++ = value;
*((long*)variable)++ = value;
*((long*)variable)++ = value;
thanx in advance
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- References:
- malloc realloc and pointers
- From: ravi
- malloc realloc and pointers
- Prev by Date: Re: partial initialized array
- Next by Date: Re: memcat fn
- Previous by thread: Re: malloc realloc and pointers
- Next by thread: binary search
- Index(es):
Relevant Pages
|