:: Re: [DNG] Making sense of C pointer…
Startseite
Nachricht löschen
Nachricht beantworten
Autor: Rainer Weikusat
Datum:  
To: dng
Betreff: Re: [DNG] Making sense of C pointer syntax.
Emiliano Marini <emilianomarini82@???> writes:
> char *p;
> p="01234"; /* skeezy, but makes the point */
>
> Warning! Here "p" is pointing to nowhere, you don't know which memory
> locations are writing to.


The 'memory location' (if any) reserved for the pointer p itself by the
compiler, IOW, this is totally correct.

>
> char *p;
> *p=malloc...*
> p="01234"; /* skeezy, but makes the point */


And this is a memory leak as the pointer returned by malloc is
overwritten.