+ 2

Are they same *ptr++ and ++*ptr?? IN C LANGUAGE. Explain it.

1st Jul 2019, 4:35 PM
Gaurav Rawat
Gaurav Rawat - avatar
4 Réponses
+ 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.
1st Jul 2019, 4:43 PM
Airree
Airree - avatar
+ 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
1st Jul 2019, 5:42 PM
tejaswi kanneganti
tejaswi kanneganti - avatar
+ 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.
1st Jul 2019, 9:47 PM
Rebecca Stancliffe
Rebecca Stancliffe - avatar