C Programming - Pointers - Discussion

Discussion Forum : Pointers - True / False Questions (Q.No. 1)
1.
Are the expression *ptr++ and ++*ptr are same?
True
False
Answer: Option
Explanation:
*ptr++ increments the pointer and not the value, whereas the ++*ptr increments the value being pointed by ptr
Discussion:
5 comments Page 1 of 1.

Aashish Gaikwad said:   1 decade ago
*ptr++ is same as *ptr+1 .means address of pointer increments. eg. *ptr=3000 to *ptr+1=3002. Its not incrementing VALUE AT ALL.

But when write ++*ptr.. it increments the VALUE THAT IS POINTED BY POINTER *ptr.address of *ptr remains constant.

E.g. address of *ptr is 3000 and value that it points is 4.

When we write ++*ptr, value 4 increments by 1 and becomes 5.
address of *ptr remains constant as 3000.

Rahul said:   1 decade ago
The ++ operator have higher precedence than *. So in in case with *ptr++ equals to *(ptr++) so it will increments the Address of the Pointer not the Value. But in case with ++*ptr equal to ++ (*ptr) in this case the Value which Pointed by Pointer.

SBoy said:   8 years ago
Post increment/decrement has higher precedence than *.
So *ptr++ == *(ptr++).

Pre increment/decrement has same precedence as * and because of right associativity.
*++ptr = *(++ptr).

Jayesh Patil said:   7 years ago
*ptr is equivalent to?

a) *ptr
b) ptr++
c) ++*ptr
d) None of the above.

Please answer this.

Pugal said:   5 years ago
@Jayesh.

*ptr only.

Post your comments here:

Your comments will be displayed after verification.