The compiler does not check for illegal memory access and your program will cause undefined behaviour or may even crash (segmentation fault). The behaviour is unpredictable and next time you run your program, it may crash.
Few things about your code:
The signature of main
should either be int main(void)
or
int main(int argc, char *argv[])
.
The comment for this statement is wrong.
node->pkeys = malloc(2*sizeof(int)); // creates a pointer pkeys in heap
You created the pointer pkeys
when you allocated memory and made node
point to it. This statement is dynamically allocating memory for array of 2 int
s and making pkeys
point to it. So when you do node->pkeys = temp
, you lose handle on the dynamically allocated array and will cause memory leak. So before reassigning pkeys
, you must free
the memory it points to.
free(node->pkeys);
// now reassign node->pkeys