0

I was doing the exercise of Operating Systems: Three Easy Pieces chapter 14 Memory API.

And I am wondering why segmentation fault is not thrown when I didn't use the p variable?

#include <stdlib.h>
#include <stdio.h>

int main(){
  int* p = NULL;
  // if I print the p variable an segmentation fault is thrown.
  // but if I am not, nothing will happen.
  //printf("%d\n",*p);
  free(p);
}
jesse
  • 29
  • 2
  • It is defined that "If a null pointer is passed as argument, no action occurs." [link] https://www.tutorialspoint.com/c_standard_library/c_function_free.htm – MissSergeivna May 25 '22 at 14:45
  • But when I print it, an segmentation fault will be thrown. – jesse Aug 03 '22 at 05:33

0 Answers0