0

please help

please explain null pointers as described null pointer has a value of 0 in standard libraries but executing following code i get errors for ex - int *p = NULL; cout << *p << endl; return 0; shows segmentation fault error thanks for your answers

17th Aug 2021, 4:51 PM
Rinchin Khandu Khochhilu
3 ответов
+ 2
pointers are special variables that take address from another variable. in your case, you assigned NULL right when you declared it. take the NULL value to another variable and then reference it when assigning a pointer to another variable. eg-: int a = NULL; int *p; p = &a; cout << *p << endl; although the complier will warn you that you're converting non-pointer type from 'int' to NULL so it's better to use integer 0
17th Aug 2021, 4:59 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 1
You're defining p as a pointer to the memory address 0 Then you try to read the value at that memory address, but that is illegal, and your program has been arrested for trying to do so
17th Aug 2021, 5:03 PM
Angelo
Angelo - avatar
17th Aug 2021, 5:08 PM
Simon Sauter
Simon Sauter - avatar