Skip to content

Instantly share code, notes, and snippets.

@anhldbk
Created July 5, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhldbk/3356c38b21ac918d7941f4edeeb5354e to your computer and use it in GitHub Desktop.
Save anhldbk/3356c38b21ac918d7941f4edeeb5354e to your computer and use it in GitHub Desktop.
C/C++ : Returning values by reference
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