Re: a quick malloc question

From: chaoith (aaa_at_aaa.com)
Date: 09/27/03


Date: Sat, 27 Sep 2003 06:38:36 +0800

drejcicaREMOVE@volja.net wrote:
> Hello,
> if I use a variable multiple times within my program, is it better to
> declare it as a pointer and malloc() it every time (if the value of the
> variable is changed many times)?

It is not the reason to use malloc().

>If it's not a pointer, does it lead to
> a memory leak?

Look into stdlib.h and see the malloc() declaration.

> However, if it is a pointer, I can use one and the same
> address every time I change its value.

Go to buy a book on C.



Relevant Pages

  • Re: a quick malloc question
    ... > if I use a variable multiple times within my program, ... > declare it as a pointer and mallocit every time (if the value of the ... It is not the reason to use malloc(). ...
    (comp.unix.programmer)
  • Re: malloc + 4??
    ... >> Providing a prototype of malloc() yourself is arguably not valid ... >> 2 Provided that a library function can be declared without ... >> permissible to declare the function and use it without ... >> including its associated header. ...
    (comp.lang.c)
  • Re: Pointer dereference rather than sizeof?
    ... The remark about casting the ... return value of malloc ("the proper method is to declare ... then explicitly coerce") needs to be rewritten. ...
    (comp.lang.c)
  • Re: IS this a proper way of freeing memory with free()
    ... remember a few years ago when one of the versions of gcc (can't remember ... Or perhaps the system's stdlib.h didn't declare malloc()? ... it would be very surprising. ...
    (comp.lang.c)
  • a quick malloc question
    ... if I use a variable multiple times within my program, ... declare it as a pointer and malloc() it every time (if the value of the ... If it's not a pointer, ...
    (comp.unix.programmer)