c - Reaching definitions involving pointers -
suppose have piece of code:
int x = 100; int* p = &x; *p = 20; print(x); //<= reaching defitition of x?
it output 20 upon execution.
problem statement reaching definition of print(x)
, initial assignment or pointer assignment?
also in following code:
void sub(int* p) { *p = 20; } int x = 100; sub(&x); print(x); //<= reaching defitition of x?
the same problem exists. special case of reaching definitions analysis, or require special algorithm process it?
you need understand more how pointers work imagine have 1 tv , 2 remote controls in first example, variable x(remote control) has value (100) , address (tv). comes pointer *p points same address x (second remote control same tv). when change value (tv channel) of *p, expect value of x changed accordingly. both *p , x holds value 20(same tv channel), , same address (2 remotes same tv)
i hope bit more clear now
Comments
Post a Comment