PIC10B_lecture1

PIC10B_lecture1 - Pointers: * and & Allocating...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory Pointers A. Barbaro UCLA PIC 10B Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory Outline for Today: Pointer review (7.17.2 of Big C++ ) 1 Pointers: * and & 2 Allocating dynamic memory 3 The NULL pointer 4 Deallocating dynamic memory Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory Creating a pointer int* p; creates a pointer to an integer This means that it creates a pointer to a spot in memory, and it will expect to find an integer there Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory Creating a pointer int* p; creates a pointer to an integer This means that it creates a pointer to a spot in memory, and it will expect to find an integer there You can create a pointer to any type of object: double* p1; string* p2; Circle* p3; Contact* p4; Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory Creating a pointer int* p; creates a pointer to an integer This means that it creates a pointer to a spot in memory, and it will expect to find an integer there You can create a pointer to any type of object: double* p1; string* p2; Circle* p3; Contact* p4; This means that the compiler expects to find a double, string, Circle, or Contact at p1, p2, p3, and p4, respectively. Note that p1 through p4 are addesses in memory. Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory &x One way to initialize a pointer: point to an object which already exists! int* p; int x = 2; p = &x; The &x can be read as "the address of x". So what this code does is Pointers: * and & Allocating dynamic memory The NULL pointer Deallocating dynamic memory &x One way to initialize a pointer: point to an object which already exists!...
View Full Document

Page1 / 22

PIC10B_lecture1 - Pointers: * and & Allocating...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online