Cognzant Technology Solutions Interview Question
Software Engineer / DevelopersWell, according to standard, postfix operator has higher priority than prefix, so last should be readed as ++(p++)
in second last line,we can also write it as ++*(p++)...bcoz increment operator has more priority then * operator. ..so first post increment operator will b applied to p ,after this,pre increment operator will be applied to value at p.
in last second pre increment and post increment both operator have same priority and both are applied on same variable so it will cause a lvalue problem.
in second last line,we can also write it as ++*(p++)...bcoz increment operator has more priority then * operator. ..so first post increment operator will b applied to p ,after this,pre increment operator will be applied to value at p.
in last second pre increment and post increment both operator have same priority and both are applied on same variable so it will cause a lvalue problem.
in case of ++*p++ u r dealing with two different storage.
- Anonymous July 09, 20111. *p
2. p
++*p is increasing the value pointed by p by one and p++ is increasing the value of p so there wont be any issue even though p++ is getting executed first.
But in case of ++i++ first i++ is getting executed which is returning a temporary object now u cant do ++(i++) because as soon as the statement get executed that temporary object will vanish so lvalue is required if u want to increase.
Though I feel that interpretation of ++i++ could be both (++i)++ or ++(i++) former is OK but latter will give u compilation error. Depends on compiler implementation which one it is choosing.