Why *ptr points to NULL? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

1st Aug 2018, 11:48 PM
RainStorm
RainStorm - avatar
3 Answers
+ 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
2nd Aug 2018, 1:02 AM
apex137
apex137 - avatar
+ 1
Robin, your answer is very clear , thanks
2nd Aug 2018, 4:40 AM
RainStorm
RainStorm - avatar
2nd Aug 2018, 4:49 AM
RainStorm
RainStorm - avatar