409 views
0 votes
0 votes
For this statement->printf ("%s",*--*++cpp+3);

What will be the order of precedence according to pointer arithmetic?

2 Answers

2 votes
2 votes
See here you might be confused in ++,-- ( Unary plus/minus )   .These operator are have more precedence than * ,as well as +(binary plus). And * has more precedence than +

now ++,-- have been distinguish from R->L associativity rule . So ++ has more precedence.

and more over two * can be distinguish also by using L->R associativity rule.(Std.book Dennis ritchie)

Here cpp is an identifier.

now comes to the problem.

first ++cpp is evaluated let result is x  ->  then --(x) result is y like wise. ->left side *(y) result z -> right side *(z) result may be k

then finally k+3
1 votes
1 votes

Based on the precedence of operators given in https://en.cppreference.com/w/c/language/operator_precedence

*--*++cpp+3
= *--*(++cpp)+3 (++ has higher precedence than + )
= *--(*(++cpp))+3 (deference has higher precedence than + )
= *(--(*(++cpp)))+3 (-- has higher precedence than + )
= ( * ( -- ( * ( ++ cpp ) ) ) ) + 3  (deference has higher precedence than + )

Related questions

4 votes
4 votes
1 answer
2
Rohan Mundhey asked Nov 5, 2016
982 views
0 votes
0 votes
1 answer
3
Prakhar Yadav 1 asked Aug 6, 2018
497 views
What is a variable pointer? please note the question is not asking about pointer variables, but the specific term.
0 votes
0 votes
2 answers
4
ermp888 asked Jun 27, 2018
1,622 views
Can you write another expression which does the same job as ++*ptr ?