References must be initialized - C++ Data Type

C++ examples for Data Type:Reference

Description

References must be initialized

Demo Code

#include <iostream>

int main(int argc, const char* argv[]) {
  int x = 3;//from   w  w w. ja  v  a 2  s . c  o m
  //int& y;  // Error y must be initialized

  int& y = x;

  std::cout << "x = " << x << std::endl << "y = " << y << std::endl;
  y = 7;
  std::cout << "x = " << x << std::endl << "y = " << y << std::endl;
  return 0;
}

Result


Related Tutorials