Created
March 4, 2014 12:00
-
-
Save rjchatfield/9345223 to your computer and use it in GitHub Desktop.
Who needs help with references and dereferencing? I just made this tiny program to help me understand what `int *myInt` meant at different places.
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
#include <iostream> | |
using namespace std; | |
void myFunc(int *r) //-- If you dereference this `r`, you'll get an int | |
{ | |
cout << " r: " << r << endl; //-- `r` is just a reference | |
cout << " *r: " << *r << endl; //-- Dereference a reference, gives me an int | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
int myInt = 69; | |
cout << " myInt: " << myInt << endl; //-- `myInt` is an int | |
cout << "&myInt: " << &myInt << endl; //-- `&myInt` is an reference | |
myFunc(&myInt); //- & is a reference | |
return 0; | |
} | |
/* | |
myInt: 69 | |
&myInt: 0x7fff5fbff8fc | |
r: 0x7fff5fbff8fc | |
*r: 69 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment