Code: Select all
int i = 4;
int *pi = &i;
int j = *pi;
int *pj = &j;
Code: Select all
int i = 4;
int *pi = &i;
int j = *pi;
int *pj = &j;
Code: Select all
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
No. pj equals &j.KemyLand wrote:This is somewhat controversial to me. It is better to jump directly to code:
Now, is pj == &i?Code: Select all
int i = 4; int *pi = &i; int j = *pi; int *pj = &j;
That will depend on what you do with i and j, and how you have your compiler to optimize. With optimization turned off, pj != &i.KemyLand wrote:Now, is pj == &i?
Actually, the result would be quantum mechanics. The moment you try to observe it from code, it stops doing thateryjus wrote:The result would be pj == &i.
Nope, once you do something like "if(pj == &i)" the compiler must make them two different variables to ensure the correctness.eryjus wrote:However, if you never assign a new value to i or j and don't do anything to change their values and have the compiler set to optimize (not sure what level will trigger this), but the compiler will optimize one of the variables out of existence. The result would be pj == &i.
You're right.max wrote:Nope