Created
January 16, 2012 15:11
-
-
Save domenicomonaco/1621289 to your computer and use it in GitHub Desktop.
REWF A a Int a
This file contains hidden or 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
| /* | |
| AdrianH | |
| re: what is the difference between int& and int | |
| hello, | |
| In some code i see some definitions like that "int& a" and I wonder what is the difference with "int a". | |
| By the way, is it different between "char* c" and "char *c " | |
| Thank you very much and best regards, | |
| starbucks | |
| :smirk: Newbies. LOL, JK. | |
| Seriously, your question is one that some people have difficulties with. C/C++ don't care about whitespaces and even less about whitespaces or lack thereof between punctuation and words/punctuation. | |
| Expand|Select|Wrap|Line Numbers | |
| */ | |
| char* c; | |
| /*is equivalent to | |
| Expand|Select|Wrap|Line Numbers*/ | |
| char *c; | |
| /*is equivalent to | |
| Expand|Select|Wrap|Line Numbers*/ | |
| char*c; | |
| /*is equivalent to | |
| Expand|Select|Wrap|Line Numbers*/ | |
| char | |
| * | |
| c; | |
| /*As for int& a, that is a declaration of a reference to an int. It is required to be initialised to something, unlike a int * which you don't have to initialise (though you probably should). Think of it like borrowing an int, or aliasing an int. Take this for example: | |
| Expand|Select|Wrap|Line Numbers*/ | |
| int a = 5; | |
| int & refA = a; | |
| refA = 6; | |
| printf("a == %d, refA == %d\n", a, refA); | |
| printf("%p == %p", &a, &refA); | |
| /* | |
| You can reference any type, be it a base type or user defined type. | |
| Hope this helps. Oh, and the only stupid question is the unasked one. Don't feel bad, I'm just in a weird mood. ;) | |
| Adrian */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment