Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- //Demo pointers
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int* pAPointer; //Declare pointer
- int* pScore; //Declare and initialize pointer
- int score = 1000;
- pScore = &score; //assign pointer pScore address of variable score
- cout << "Assigning &score to pScore\n";
- cout << "&score is: " << &score << "\n"; //Address of score variable
- cout << "pScore is: " << pScore << "\n"; //Address stored in pointer
- cout << "score is: " << score << "\n";
- cout << "*pScore is: " << *pScore << "\n\n"; //value pointed to by pointer
- cout << "****Adding 500 to score****\n";
- score += 500;
- cout << "score is: " << score << "\n";
- cout << "*pScore is: " << *pScore << "\n\n";
- cout << "****Assigning &newScore to pScore****\n";
- int newScore = 5000;
- pScore = &newScore;
- cout << "&newScore is: " << &newScore << "\n";
- cout << "pScore is: " << pScore << "\n";
- cout << "newScore is: " << newScore << "\n";
- cout << "*pScore is: " << *pScore << "\n\n";
- cout << "****Assigning &str to pStr****\n";
- string str = "score";
- string* pStr = &str; //Pointer to string object
- cout << "str is: " << str << "\n";
- cout << "*pStr is: " << *pStr << "\n";
- cout << "(*pStr).size() is: " << (*pStr).size() << "\n";
- cout << "pStr->size() is: " << pStr->size() << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement