100 likes | 209 Views
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?.
E N D
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? • 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.
What can be 'pointed to'? • Objects • Functions • Variables • Hardware (Wunderboard IO)
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"
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
In summary • Try to use pointers in your labs/assignments to gain experience • In 'real coding' pointers are not ALWAYS the answer