+ 1
Why *ptr points to NULL?
#include <stdio.h> #include <stdlib.h> void Point(int*); int main() { int* ptr = NULL; Point(ptr); printf("%p",ptr); free(ptr); return 0; } void Point(int* ptr) { ptr = (int*)malloc(sizeof(int)); } https://code.sololearn.com/ct0XjpLK9BBy/?ref=app
3 Respuestas
+ 1
Because you never assigned an actual value to the address the pointer points to. Simple as that.
Remember that pointers are only directions to an address in memory, and they will never hold the actual value. That can be accessed by following the pointer to where it is really being stored
+ 1
Robin, your answer is very clear , thanks
+ 1
Here is my solution code
https://code.sololearn.com/cp71Ri3tn8LM/?ref=app