//To compile: g++ [source_code.cpp] -o [exec_file] // replace [soure_code.cpp] with the filename, // replace [exec_file] with the executable file name // i.e., g++ c++_basics.cpp -o run //Note: if the output redirect is not given, i.e., the "-o [exec_file]" part is missing // then the default executable name is a.out //To run the program, simply run the executable: ./[exec_file] // i.e., ./a.out (if your executable file is a.out) #include //input/output stream library using namespace std; void swap_val(int x, int y){ int temp = x; x = y; y = temp; cout << "x: " << x << endl; cout << "y: " << y << endl; //print out addr of x and y cout << "&x: " << &x << endl; cout << "&y: " << &y << endl; } void swap_ref(int &x, int &y){ int temp = x; x = y; y = temp; cout << "x: " << x << endl; cout << "y: " << y << endl; //print out addr of x and y cout << "&x: " << &x << endl; cout << "&y: " << &y << endl; } //main function: entry point of the program int main() { // //declare and initialize the variable, grade // int grade = 0; // int again = -1; // //prompt the user for an input, and store it into 'grade' // do { // cout << "Enter your grade: "; // cin >> grade; // //output the grade to the console // // endl: end of the line // cout << "Your grade is: " << grade << endl; // if (grade >= 90) // cout << "A" << endl; // else if (grade >= 80) // cout << "B" << endl; // else if (grade >= 70) // cout << "C" << endl; // else if (grade >= 60) // cout << "D" << endl; // else // cout << "F" << endl; // cout << "Would you like to enter a different grade? 1-yes, else-no: "; // cin >> again; // } while (again == 1); int a = 5, b = 10; //swap_val(a, b); swap_ref(a, b); cout << "a: " << a << endl; cout << "b: " << b << endl; //print out addr of a and b cout << "&a: " << &a << endl; cout << "&b: " << &b << endl; return 0; }