CMPSC 16 Lecture Notes - Lecture 9: Null Pointer, Segmentation Fault, Array Data Structure

42 views2 pages
8 Nov 2018
School
Course
Professor

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents