Hi,
here there's an example code that creates a memory leak.
My problem is to call free on modified pointer.
I mean if I need to perform some operations on 'test' so I change it toCode:int num=10; char *test; int i=0; if ((test = calloc(num, sizeof(char *))) == NULL) { puts("allocation error!"); return 1; } puts("Mem allocated"); printf("Insert name: "); scanf("%s",test); printf("your name is %s\n", test); //NEED TO PERFORM SOME OPERATIONS test=&test[1]; <-------- pointer changed printf("%s\n",test); //free(test); return 0; }
point to the next char there's no way to free up the memory correctly? So Do I always have to use a backup pointer (a temporary pointer) without change the original one?
Thanks in advance