Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // More tutorials at BrandonHok.com
- #include <iostream>
- // C++ Crackdown 4.1 - Pointer Beginnings
- // What are pointers you may ask?
- // A pointer in its simplest term is just
- // an arrow that points to a specific memory address
- // -> 1008 Fire Storm Miami
- // What is the purpose of a pointer?
- // To save memory space and for large variables.
- // Metaphor Example
- // If I live on 1008 Fire Storm Miami
- // Then the pointer is literally the ->
- // Or sign that says [To The Right Is 1008 Fire Storm Miami]
- // A sign just points to an address, but the actual sign is not the house.
- // A sign just "points" to the specific desired address.
- // Metaphor Example
- // We are at a parking lot together.
- // I ask you to tell me where is the red car.
- // You point with your finger at the red car.
- // Obviously the answer is not your finger, but I can look
- // at your finger and it will point me towards the answer.
- // I can ask you to use your other fingers to point me at different
- // color cars (where other data points are found).
- int main()
- {
- // Section 1
- // Type the following code below until Section 2.
- // Declare our first variable
- int y[5] = { 10,2,3,4,5 };
- // declare our pointer and intitalize it to the address(&) of y
- int *x = &y[0];
- // Take a look at the numbers and check it out
- // How about changing *x to &x, you'll see something special like a computer address
- // Surprise!
- std::cout << y << std::endl;
- system("pause");
- // Section 2
- // Now you may type in the rest of the code =)
- // Look carefully and see what are the differences between thw two
- std::cout << x << std::endl;
- std::cout <<*x;
- std::cout << *(x + 3);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement