in Programming in C
1,611 views
0 votes
0 votes
Can you write another expression which does the same job as  ++*ptr ?
in Programming in C
by
1.6k views

2 Answers

2 votes
2 votes

In operator precedence list ++ and * have same priority. so we must go with associativity (Right to left).

lets take an example in an array A

value 4 6 9
address 100 200 300

at first  if we have ptr = A, it means address of first element of A i.e. 100 will be stored in ptr.

now ptr=100.

if we write *ptr , it means value of ptr i.e. 4

if we use ++ (pre-increment operator) as ++*ptr , value of 4 will be incremented by 1 and becomes 5.

which is same as writing *ptr = *ptr + 1.

i hope you got your answer.

0 votes
0 votes
++(*p) // first take the value and then  increment the value  //

Related questions