c++ reference can not be reassigned

#include <iostream>
 
using namespace std;
 
int main () {
   // declare simple variables
   int    i;
   int    j;
   double d;
 
   // declare reference variables
   int&    r = i;
   double& s = d;
   j = 10;
   r = j;
   j = 10;
   
   i = 5;
   cout << "Value of i : " << i << endl;
   cout << "Value of i reference : " << r  << endl;
 
   d = 11.7;
   cout << "Value of d : " << d << endl;
   cout << "Value of d reference : " << s  << endl;
   
   return 0;
}

 

posted @ 2018-09-06 10:47  友哥  阅读(134)  评论(0编辑  收藏  举报