Advertisement
okelikai

pointerTest

Jan 9th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. // BK, testing out pointers for makeup quiz
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int varOne, varTwo, addOutput; // basic input and output variables
  8.     int * varOneLocation, * varTwoLocation; // initialized as pointers
  9.    
  10.     cout << "\e[1mAddition Calculator\e[0m"  << endl  // for making program pretty
  11.          << "What is the first number?"      << endl;
  12.     cin  >> varOne;                                   // grabbing first value from user
  13.     cout << "What is the second Number?"     << endl;
  14.     cin  >>  varTwo;                                  // grabbing second value from user
  15.    
  16.     varOneLocation = &varOne; // pointing to varOne memory location
  17.     varTwoLocation = &varTwo; // ''
  18.    
  19.     addOutput = varOne + varTwo; // basic math
  20.    
  21.     cout << varOne << '+' << varTwo << '=' << addOutput << endl
  22.          << "The memory location of the first variable is: "  << varOneLocation << endl
  23.          << "THe memory location of the second variable is: " << varTwoLocation << endl;
  24.    
  25.     cout << endl << endl
  26.          << "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."
  27.         ;   // "paragraph" explaining code
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement