C++ lecture 17

18 5 0
C++ lecture 17

Đ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

C++ Programming Lecture 17 Pointers – Part II The Hashemite University Computer Engineering Department (Adapted from the textbook slides) Outline       Introduction The Relationship Between Pointers and Arrays Pointer Expressions and Pointer Arithmetic sizeof Operator for Arrays and Pointers Functions call by reference using pointers Examples The Hashemite University The Relationship Between Pointers and Arrays I  Arrays and pointers are closely related     Array name is a constant pointer that contains the address of the first element in the array (you cant move this pointer to points to another element of the array) Pointers can array subscripting operations Having declared an array b[ ] and a pointer bPtr You have two ways to make bPtr points to the first element of the array - bPtr is equal to b bptr == b - bptr is equal to the address of the first element of b bptr == &b[ ] The Hashemite University The Relationship Between Pointers and Arrays II  Accessing array elements with pointers  Element b[ n ] can be accessed by *( bPtr + n )   Array itself can use pointer arithmetic    Called pointer/offset notation b[ ] same as *(b + 3) Note : *(b+3) is correct, while *(b+=3) is not correct because you try to move this pointer to another location Pointers can be subscripted (pointer/subscript notation)  bPtr[ ] same as b[ ] The Hashemite University Example Array name is pointer to first element char t[5]={'a','b','c','d','e'}; cout

Ngày đăng: 12/10/2021, 21:09

Mục lục

    C++ Programming Lecture 17 Pointers – Part II

    The Relationship Between Pointers and Arrays I

    The Relationship Between Pointers and Arrays II

    Example --Array name is pointer to first element

    Pointer to Char and Strings

    Pointer Expressions and Pointer Arithmetic I

    Pointer Expressions and Pointer Arithmetic II

    sizeof Operator and Arrays

    sizeof Operator and Pointers

    Calling Functions by Reference

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan