There are no temp pointer to free. The pointers are not allocated
dynamically, so need not to be released. It's the contents that the
pointer points to, that needs to be released.
Your print is wrong.
It should be *a to write the integer value that a points to.
/pwm
On Fri, 1 Jun 2007, Jan Mura wrote:
> Hello,
>
> I would like to ask and clear the problem of freeing a memory previously
> allocated.
> I have got a program and this a simple example of something similar:
>
> #include<stdlib.h>
> #include<stdio.h>
>
> void chng (int **in_a)
> {
> int *temp;
>
> temp = malloc(sizeof(int));
> *temp = 1;
> *in_a = temp;
>
> }
>
> int main()
> {
> int *a;
>
> chng(&a);
>
> printf ("a = %d\n", a);
> free (a);
>
> return 0;
> }
>
> And I would like to know if this free (a);
> at the end of main() frees also a temp pointer which is used in chng()
> function.
> It should to do this because it adress the same part of memory if I
> understand it correctly.
>
> If you notice any other problem with the thing above, plese tell me.
>
> Thank you very much
>
> Jan Mura
> jan...@vo...
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|