//Pre-processor directives #include #include using namespace std; // Function prototypes void simpleVersion(); int max(vector nums); void moreInteresting(); // The main method - execution begins here int main(){ cout << "Calling simple version" << endl; simpleVersion(); cout << "Calling more interesting version" << endl; moreInteresting(); // Returning 0 in the main method indicates that // everything went okay return 0; } // Returns the maximum int in the vector int max(vector nums){ int max = nums[0]; for( int i = 1; i < nums.size(); i++ ){ if( nums[i] > max ){ max = nums[i]; } } return max; } void simpleVersion(){ vector nums; nums.push_back(1); nums.push_back(2); nums.push_back(3); int val = max(nums); cout << val << endl; } void moreInteresting(){ vector nums; nums.push_back(1); nums.push_back(2); nums.push_back(3); // In C++, this copies the contents of nums into nums2 vector nums2 = nums; // We then change nums so its max is 15 nums[0] = 15; // Notice the change above doesn't affect nums2! The max for // nums2 is still 3 int val = max(nums2); cout << val << endl; }