Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active August 14, 2016 05:41
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 JoshCheek/7f13eadc46a4aee0d66688dd424e3d85 to your computer and use it in GitHub Desktop.
Save JoshCheek/7f13eadc46a4aee0d66688dd424e3d85 to your computer and use it in GitHub Desktop.
C++'s reference type antagonizes ontological clarity
$ g++ reference.cpp && ./a.out
num1: 0, num2: 0
num1: 1, num2: 1
num1: 2, num2: 2
#include <stdio.h>
int main() {
int num1 = 0;
int& num2 = num1;
printf("num1: %d, num2: %d\n", num1, num2);
num1 = 1;
printf("num1: %d, num2: %d\n", num1, num2);
num2 = 2;
printf("num1: %d, num2: %d\n", num1, num2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment