The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
59 views
For this statement->printf ("%s",*--*++cpp+3);

What will be the order of precedence according to pointer arithmetic?
asked in Programming by (61 points) | 59 views

2 Answers

+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
answered by (477 points)
0 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 + )

answered by (373 points)

Related questions

+3 votes
1 answer
2
asked Nov 5, 2016 in Programming by Rohan Mundhey Active (3.7k points) | 267 views
0 votes
1 answer
6
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,049 questions
53,194 answers
184,531 comments
70,402 users