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.
is equivalent to
is equivalent to
is equivalent to
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:
-
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