+ 2

Why giving different value of 1st and 5th even if same pointer and everything same .

https://code.sololearn.com/cWRGsWWtmyJL/?ref=app

19th Mar 2022, 9:50 AM
Abhay mishra
Abhay mishra - avatar
5 Respuestas
+ 1
Increments applying on pointers, not on it's contents. Post fix operator has highest precedence than *dereference operator. so It's evaluated *p++ as *(p++) , and it's a post increment operation so first value is used in print after then increments.. pre fix operator and dereference has same precedence but associativity is right to left. so *++p is evaluated as *(++p) => *(p=p+1)
19th Mar 2022, 10:17 AM
Jayakrishna 🇮🇳
+ 2
Observe that p gets incremented twice by lines 12 and 13. Now p is two positions higher than it started out, so it points to the third element, which holds the value 2.
19th Mar 2022, 9:59 AM
Brian
Brian - avatar
+ 2
Yes. Because p is in scope within all of main(), if you change it anywhere in main() (even in a function argument) then the change remains in effect thereafter - until the next change.
19th Mar 2022, 10:14 AM
Brian
Brian - avatar
+ 2
Ok thanks
19th Mar 2022, 10:15 AM
Abhay mishra
Abhay mishra - avatar
+ 1
Brian So in pointer specific print also chang value of another coming ?
19th Mar 2022, 10:05 AM
Abhay mishra
Abhay mishra - avatar