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
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
+ 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