CMPSC 16 Lecture Notes - Lecture 9: Null Pointer, Segmentation Fault, Array Data Structure
Document Summary
Dereferencing a pointer: *p when p is a pointer that points to a var. Gets the memory location from p and then going to that memory location to get the value there. When you dereference it, c++ needs to know how many bytes to take from the memory location. If a pointer does not point to a variable, then there will be junk files/data in the pointer (the pointer was not initialized) Causes a segmentation fault when the *pointer is called (dereferencing the pointer) Dereferencing a null pointer causes a segmentation fault. Declaring 2 pointers: int *p = &y, *q; Pointer to a pointer to an integer: **pointer. P2 --> p1 --> x = 10. *p2 gives the memory address stored in p1. Store the value of the 0th term of an array in a pointer: pointertype *p = arrayname; Pointername[0] or *q or *arrayname to access the 0th element of an array.