1 / 8

C++ Pointers Review

C++ Pointers Review. Overview. What is a pointer Why do I care? What can be 'pointed to'? Example. What is a pointer. A pointer is essentially an address It tells your code "manipulate whatever is 'here'". Why do I care?.

donnan
Download Presentation

C++ Pointers Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ Pointers Review

  2. Overview • What is a pointer • Why do I care? • What can be 'pointed to'? • Example

  3. What is a pointer • A pointer is essentially an address • It tells your code "manipulate whatever is 'here'"

  4. Why do I care? • Pointers give the power to improve program memory usage and speed (no NEED to copy data) • Pointers let you 'return' more than one value from a function (direct manipulation of original) • Most languages DON'T have them. This is a reason C and C++ are so used.

  5. What can be 'pointed to'? • Objects • Functions • Variables • Hardware (Wunderboard IO)

  6. Example • int x = 5; • x is synonymous with 5 • "The integer x" is as valid as "The integer 5" • int* y = &x; • y is a pointer to a memory location holding an integer • x is an integer and &x is the address of integer x • "Integer pointer y point to integer x"

  7. Using pointers in Function Parameters • int someFunc(int value) • manipulating 'value' has no effect on the original • int someFunc(int *value) • manipulating 'value' modifies the original

  8. In summary • Try to use pointers in your labs/assignments to gain experience • In 'real coding' pointers are not ALWAYS the answer

More Related