Mega Code Archive

 
Categories / C++ Tutorial / Data Types
 

References must be initialized

#include <iostream> using std::cout; using std::endl; int main() {    int x = 321;    int &y = x;    cout << "x = " << x << "    y = " << y << endl;    y = 123;    cout << "x = " << x << "    y = " << y << endl;    return 0;  } x = 321 y = 321 x = 123 y = 123