Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <string>
- using namespace std;
- int main()
- {
- // Pointers vs. References
- int myInt = 5;
- // Reference to 'myInt'
- int& anotherInt = myInt;
- anotherInt = 10;
- // Modified value of 'myInt'
- cout << "myInt = " << myInt << endl;
- // Pointer to myInt;
- int* ptr = &myInt;
- // Prints address of pointer
- cout << ptr << endl;
- // Dereferencing pointer to show actual content of address
- cout << *ptr << endl;
- // Pointers and arrays
- int numbers[] = { 0, 1, 2, 4, 5 };
- // Points to first value of array
- int* numPtr = numbers;
- // Will print '0'
- cout << *numPtr << endl;
- // Will print '1' (pointer arithmetic)
- numPtr++;
- cout << *numPtr << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement