1,658 views
0 votes
0 votes
Can you write another expression which does the same job as  ++*ptr ?

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

1 votes
1 votes
2 answers
1
ermp888 asked Jul 1, 2018
516 views
13. What does the error "Null Pointer Assignment" mean and what causes this error?
0 votes
0 votes
1 answer
2
ermp888 asked Jun 30, 2018
669 views
6. Would the following program compile?main( ) { int a = 10, *j; void *k; j = k = &a; j++ ; k++; printf ("\n %u %u", j, k ) ; }Please explain above program with some exam...
1 votes
1 votes
1 answer
3
ermp888 asked Jun 30, 2018
842 views
(5) Would the following program give a compilation error or warning?main() { float i = 10, *j; void *k; k=&i; j= k; printf("\n%f", *j); }
1 votes
1 votes
1 answer
4