1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Programming in C++ - Chapter 11: Pointer variables

27 70 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 27
Dung lượng 513,97 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

On completion of this chapter students will know how to: Declare and initialize pointer variables, pass addresses to functions, return an address from a function, reserve memory during execution, link classes with accessor functions.

Trang 1

Chapter 11 – Pointer Variables

Trang 2

Declared with data type, * and identifier       type*  pointer_variable;

* follows data type

– Usually no space between so more obvious – Space allowed, so 1 or more would still work

Reserves space for storage

Must initialize or assign address

Lesson 11.1

Trang 4

– Example:  width_ptr

Lesson 11.1

Trang 6

Lesson 11.1

Trang 7

Declaration of function header to indicate a reference

Trang 8

Somewhat flexible in declaration or header      

Trang 10

Header

Function

Body

Trang 12

Lesson 11.4

Trang 13

from Function

Lesson 11.5

Example:  Function declaration and header    double*  get_array_address (double [ ] );    double*  get_array_address (double c[ ] )

Now a return statement with variable thatindicates address in the function body

       return c;

 double*

Could also use

Trang 14

Lesson 11.6

Trang 18

– size is array size

Lesson 11.6

Trang 19

– size is array size

Lesson 11.6

Trang 20

Lesson 11.6

Trang 22

Lesson 11.7

Trang 24

Lesson 11.9

Trang 26

– deletes memory for single element

Lesson 11.9

Trang 27

Declare and initialize pointer variablesPass addresses to functions

Return an address from a function

Reserve memory during execution

Link classes with accessor functions

Learned how to:

Ngày đăng: 30/01/2020, 02:24