100 likes | 217 Vues
Learn what pointers are, why they matter, objects they can point to, and how to use them in functions. Experience the power of pointers for efficient memory usage and improved program speed. Remember, pointers are not always the best solution in all coding scenarios.
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