// CSE 374 Spring 2018 // Hello World C++ example // File name: .cpp or .cc #include #include const int CURRENT_YEAR = 2018; using namespace std; // REFERENCE void pig(string& s) { char first = s[0]; s = s.substr(1); s += first; s += "ay"; } int main() { // stack-allocated array: int arr[100]; // C-style heap array: int* arr = (int*) malloc(sizeof(int) * 100); // C++ style heap allocation: int* arr = new int[100]; // C-style array deletion: free(arr); // C++ style array deletion: delete [] arr; // Use "delete x;" for things that aren't arrays. cout << "What is your name? "; string name; cin >> name; pig(name); cout << "What year were you born? "; int year; cin >> year; const int age = CURRENT_YEAR - year; cout << "Hello, " << name << "!" << endl; cout << "You are " << age << " years old" << endl; return EXIT_SUCCESS; }