using references for int : reference « Data Type « C++






using references for int

  
#include <iostream>

using namespace std;

int main()
{
    int myScore = 1000;
    int& mikesScore = myScore;  // create a reference
    
    cout << "myScore is: " << myScore << endl;
    cout << "mikesScore is: " << mikesScore << endl;
    
    myScore += 500;
    cout << "myScore is: " << myScore << endl;
    cout << "mikesScore is: " << mikesScore << endl;

    mikesScore += 500;
    cout << "myScore is: " << myScore << endl;
    cout << "mikesScore is: " << mikesScore << endl;

    return 0;
}
  
    
  








Related examples in the same category

1.constant references
2.returning a reference to a string
3.Reassigning a reference
4.Taking the Address of a Reference
5.swap() Rewritten with References
6.Passing by Reference Using Pointers
7.Passing Objects by Reference
8.Passing References to Objects
9.Returning multiple values from a function using references
10.Creating and Using References for integer
11.Data Slicing With Passing by Value
12.References for int type variable