Hello!
I have a doubt about how the operation of freeing memory works.
If i write a program like this one:
Code:
#include <stdio.h>
#include <stdlib.h>
struct orderlistNode {
int number;
struct orderlistNode* nextNode;
};
typedef struct orderlistNode* orderNode;
int main(){
orderNode a = malloc(sizeof(struct orderlistNode));
orderNode b = malloc(sizeof(struct orderlistNode));
a->number = 47;
b->number = 2;
a->nextNode = b;
printf("a: %d\n", a->number);
printf("b: %d\n", b->number);
free(a);
printf("again a: %d\n", a->number);
printf("through a: %d\n", a->nextNode->number);
printf("again b: %d\n", b->number);
return 0;
}
even after freeing the variable 'a' I'm able to read it and even to navigate the list through its internal pointer! Is it normal? And if it is, how can I free the variable 'a' in a way that it can't be accessed anymore?
Thanks for your help!