Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active June 26, 2021 18:24
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/2fca3ef9d2467e8b1c7868ec4711dfd6 to your computer and use it in GitHub Desktop.
Save JoshCheek/2fca3ef9d2467e8b1c7868ec4711dfd6 to your computer and use it in GitHub Desktop.
Pretty sure C++ refs are just obfuscating syntax around pointers
// code for the screenshot in this tweet https://twitter.com/josh_cheek/status/1408853467150663680
#include "stdio.h"
void inc1(int& n) { ++ n; }
void inc2(int* n) { ++*n; }
int main(int argc, char** argv) {
int a = 0, b=0;
printf("a=%d, b=%d\n", a, b);
inc1(a); inc2(&b);
printf("a=%d, b=%d\n", a, b);
inc1(a); inc2(&b);
printf("a=%d, b=%d\n", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment