+ 2
Are they same *ptr++ and ++*ptr?? IN C LANGUAGE. Explain it.
4 Antworten
+ 3
Sachin Artani I don't think that's the case. With *ptr++, the value of *ptr will stay the same, but ptr will be incremented, meaning it will point to the next memory location (if in an array, the next element of the array). ++*ptr will just increment the value of the memory location ptr points to.
+ 2
We simply differentiate by seeing the post increment operator and pre increment operator they are same if and only if we check the value of *ptr after the execution of whole program
+ 2
Im not sure I fully understand everything that you are asking but I can hopfully give some insight onto the position of the ++
In my experiance it effects when the increment occurs.
so if ptr=0
ptr++ means it is incremented after. So the values of ptr are: 0, 1 and so on.
++ptr means it is incremented before. So the values of ptr are: 1, and so on.
I hope this helps but please correct me if I’m wrong as I’m not 100% sure myself.
I would appreciate if you could confirm this. I dont want to be the one to explain something wrong.
+ 1
In other words, you are asking the difference between increment and decrement operator.
https://www.sololearn.com/discuss/1744114/?ref=app
https://www.sololearn.com/discuss/1793856/?ref=app
https://www.sololearn.com/discuss/1837010/?ref=app
https://www.sololearn.com/discuss/1843023/?ref=app
https://code.sololearn.com/cjHQRJUG5NTf/?ref=app