Created
July 5, 2017 03:17
-
-
Save anhldbk/3356c38b21ac918d7941f4edeeb5354e to your computer and use it in GitHub Desktop.
C/C++ : Returning values by reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t counter = 0; | |
uint32_t& get_counter(){ | |
return counter; | |
} | |
int main(){ | |
uint32_t _counter = get_counter(); | |
_counter += 1; | |
cout << _counter << endl; // print 1 | |
cout << counter << endl; // print 1 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment