Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BK, testing out pointers for makeup quiz
- #include <iostream>
- using namespace std;
- int main()
- {
- int varOne, varTwo, addOutput; // basic input and output variables
- int * varOneLocation, * varTwoLocation; // initialized as pointers
- cout << "\e[1mAddition Calculator\e[0m" << endl // for making program pretty
- << "What is the first number?" << endl;
- cin >> varOne; // grabbing first value from user
- cout << "What is the second Number?" << endl;
- cin >> varTwo; // grabbing second value from user
- varOneLocation = &varOne; // pointing to varOne memory location
- varTwoLocation = &varTwo; // ''
- addOutput = varOne + varTwo; // basic math
- cout << varOne << '+' << varTwo << '=' << addOutput << endl
- << "The memory location of the first variable is: " << varOneLocation << endl
- << "THe memory location of the second variable is: " << varTwoLocation << endl;
- cout << endl << endl
- << "So the way this program works is really simple, it first initializes the values varOne and varTwo as well as addOutput, for the baseline functionality of the program, it then initializes varOneLocation and varTwoLocation as pointers in the same data type as the first variables (int). Then the program simply asks for the first and second number as it is the simple addition. After that when varOne and Two are holding data, it gives the location of them to the pointers, does the math, then outputs all of the data."
- ; // "paragraph" explaining code
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement