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

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -