tailieunhanh - Lecture C++ for everyone (2nd edition): Chapter 7 - Cay S. Horstmann

Chapter 7 - Pointers. In the game on the left, the spinner’s pointer moves to an item. a player follows the pointer and handles the item to which it points - by taking the ball or following the instructions written in the space. C++ also has pointers that can point to different values throughout a program run. pointers let you work with data whose locations change or whose size is variable. | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Seven: Pointers, Part I Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved To be able to declare, initialize, and use pointers To understand the relationship between arrays and pointers To be able to convert between string objects and character pointers To become familiar with dynamic memory allocation and deallocation Chapter Goals C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Pointers What’s stored in that variable? C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Pointers No, that one – the one I’m pointing at! C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved A variable contains a value, but a pointer specifies where a value is located. A pointer denotes the memory location of a . | C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Seven: Pointers, Part I Slides by Evan Gallagher C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved To be able to declare, initialize, and use pointers To understand the relationship between arrays and pointers To be able to convert between string objects and character pointers To become familiar with dynamic memory allocation and deallocation Chapter Goals C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Pointers What’s stored in that variable? C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Pointers No, that one – the one I’m pointing at! C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved A variable contains a value, but a pointer specifies where a value is located. A pointer denotes the memory location of a variable Pointers C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Pointers Yes, I mean x Look: I’m holding a pointer value! C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved In C++, pointers are important for several reasons. Pointers allow sharing of values stored in variables in a uniform way Pointers can refer to values that are allocated on demand (dynamic memory allocation) Pointers are necessary for implementing polymorphism, an important concept in object-oriented programming (later) Pointers C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Consider a person. A chef. A Banking Problem (Harry) Hi. Nice to see you again. C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Harry has more than one bank account. Harry Needs a Banking Program Business is GREAT with those algorithms! C++ for Everyone by Cay Horstmann

TỪ KHÓA LIÊN QUAN