Definition of expression and statement.

J

James Kuyper

somenath wrote:
....
I would like to clarify my self why I requested so. I was reading one
C text book which is famous in our country it says as mentioned.


"These instructions increase directly specify the required information
so help in faster execution. 'C' makes
efficient use of this feature by providing compound statements for
which translation can be done directly to
its corresponding machine instruction. For example: ....
So according to this logic first function "int three_more(int x)"
may be faster then the "int better_three_more(int x)". Is it not
correct ?

The text you cite is describing the difference between a=a+10 and a+=10.
The difference between three_more and better_three_more is that one uses
return x+=3; and the other uses return x+3, which is a quite different
issue.

The first pair of expression are semantically equivalent, and will
compile to the same code using a smart compiler; the second of the two
expressions may compile to better code when using a dumb compiler, but
that's a minor issue. The facts that a+=10 is marginally easer to type
and easier to understand (once you're used to it) is far more important
(this is even more important when 'a' is replaced by a long complicated
expression).

The difference between return x+=3; and return x+3; is that the first
nominally specifies a pointless change to a variable whose lifetime will
end before the changed value ever gets used. A smart compiler will
probably notice that fact and produce the same code for both statements.
However, it's still bad practice to use return x+=3; because a
maintenance programmer is likely to waste time wondering why you
specified the change to x, before realizing that it was just a coding error.
 
P

pete

Only if the expression is of an object type,
does it have a value.
hello,
an expression is a combination of one or more operators,

The original "zero or more operands"
is a better description.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top