Does this code mean : Address of b is address of a?Code:#include<stdio.h> int main() { int a,&b=a; a = 10; printf("\na = %d",a); printf("\nb = %d",b); b = 15; printf("\na = %d",a); printf("\nb = %d",b); return 0; }
Does this code mean : Address of b is address of a?Code:#include<stdio.h> int main() { int a,&b=a; a = 10; printf("\na = %d",a); printf("\nb = %d",b); b = 15; printf("\na = %d",a); printf("\nb = %d",b); return 0; }
That looks like invalid syntax, at least for C.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I don't know for sure, but it does compile and give me outputs as if a and b are aliases.
So this is not a valid C code then?
You probably compiled the code as C++. C does not have C++ style references.I don't know for sure, but it does compile and give me outputs as if a and b are aliases.
Yes.So this is not a valid C code then?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Also, aside from it not being valid C, there is no necessity for the compiler to actually store the address of a in b - all that is REQUIRED by the compiler is that it make b behave like another name of a. So it may even just say "store a in Register1, and b is also found in Register1", for the purpose of the above code.
In more complex cases, yes, then b would contain the address of the variable that it's referencing (which also means that the referenced variable can not be stored in a register).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.