"neha" <ne*********@gm ail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi
My question is : Would the expression *p++=c be disallowed by the
complier.
The answer given in the book is: No.Because here even though the vlue
of p is acced twice it is used to modify two different objects p and
*p.
so can anyone explain this answer to me detail
Your question is similar to a FAQ, did you read it before posting?:
----------------------------------------------------
4.3: Does *p++ increment p, or what it points to?
A: Postfix ++ essentially has higher precedence than the prefix
unary operators. Therefore, *p++ is equivalent to *(p++); it
increments p, and returns the value which p pointed to before p
was incremented. To increment the value pointed to by p, use
(*p)++ (or perhaps ++*p, if the order of the side effect doesn't
matter).
References: K&R1 Sec. 5.1 p. 91; K&R2 Sec. 5.1 p. 95; ISO
Sec. 6.3.2, Sec. 6.3.3; H&S Sec. 7.4.4 pp. 192-3, Sec. 7.5 p.
193, Secs. 7.5.7,7.5.8 pp. 199-200.
----------------------------------------------------
A side point:
I would never rely on the compiler to reject a nonsense code fragment.
There are some types of problems that the compiler MUST issue a diagnostic
message for, but there are other things that are totally wrong but which the
compiler does not have to diagnose.