www.openskytechnology.comDescription: Description: D:\website\syllabus\study_matreials\c++\logo_pic\logo.jpg

Training Home

Return by Reference

  _______________________________________________________________________

 

#include<iostream>

using namespace std;

int& modify()

{

static int x;

cout <<"x =" <<x<<endl;

return x;

}

int& modify1()

{

    static int i=50;

    return i;

}

int& modify2()

{

    static int a =500;  //a local variable can also be used here with a warning

    return a;

}

int main()

{

    modify() = 100;

    modify()=200;

    modify()=300;

    int& a = modify1();

    cout<<"a= "<<a<<endl;

    int xx= modify2();

    cout<<"xx= "<<xx;

}

_______________________________________________________________________

 

 

Copyright © Open Sky Technology

 

Corporate Office:  #4, RR Complex, 2nd Floor, Munnekolala, Marathahalli, Bangalore – 560037. (Landmark: near Munnekolala Bus Stop)   Mobile: 9886333765,