Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what is a statement and expression?

Reply
Thread Tools

what is a statement and expression?

 
 
vlsidesign
Guest
Posts: n/a
 
      12-07-2007
Some of the words used in programming books are foggy to me (maybe I
should revisit English one day). I looked up some terms in the
dictionary, which seem to help. In particular, statement and
expression. Here is what I gathered from a dictionary:
A statement is an expression in words.
In math, an expression is a collection of symbols expressing a
quantity.

In programming, is a statement and expression similar things? How
would you define an expression in programming, code that evaluates to
something. Control structures and loops seem to be different and in
fact contain statements and/or expressions. Thanks for any insight.
 
Reply With Quote
 
 
 
 
Dik T. Winter
Guest
Posts: n/a
 
      12-07-2007
In article <(E-Mail Removed)> vlsidesign <(E-Mail Removed)> writes:
> Some of the words used in programming books are foggy to me (maybe I
> should revisit English one day).


Using a dictionary can be confusing, especially if is a dictionary that
is not technical.

> In programming, is a statement and expression similar things?


Depends on the programming language involved. To know what the meaning
of those words actually is, you need to read the standard for the
particular language, where such terms are actually defined. In C,
every expression can be used as a statement, but not the other way
around. In other programming languages, they are quite different.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      12-07-2007
On Thu, 6 Dec 2007 18:37:51 -0800 (PST), vlsidesign
<(E-Mail Removed)> wrote in comp.lang.c:

> Some of the words used in programming books are foggy to me (maybe I
> should revisit English one day). I looked up some terms in the
> dictionary, which seem to help. In particular, statement and
> expression. Here is what I gathered from a dictionary:
> A statement is an expression in words.
> In math, an expression is a collection of symbols expressing a
> quantity.
>
> In programming, is a statement and expression similar things? How
> would you define an expression in programming, code that evaluates to
> something. Control structures and loops seem to be different and in
> fact contain statements and/or expressions. Thanks for any insight.


In C, an expression is a sequence of operators and or operands that
yields a value, or a call to a function with a void return type, which
does not yield a value. An expression can stand alone or be a
subexpression.

2 + 2

....is an expression, that happens to yield a value of 4 with type int.

Given a previous definition "int x, y = 0;", then...

x = 2 + 2 + y

....is an expression of which (2 + 2) is a subexpression, and (2 + 2 +
y) is a subexpression. This could be a subexpression of a larger and
more complex expression.

An expression becomes a statement when terminated by the statement
termination token, ';'. So:

x = 2 + 2 + y;

....is a statement.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
vlsidesign
Guest
Posts: n/a
 
      12-07-2007
On Dec 6, 6:53 pm, "Dik T. Winter" <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed)> vlsidesign <(E-Mail Removed)> writes:
> > Some of the words used in programming books are foggy to me (maybe I
> > should revisit English one day).

>
> Using a dictionary can be confusing, especially if is a dictionary that
> is not technical.
>
> > In programming, is a statement and expression similar things?

>
> Depends on the programming language involved. To know what the meaning
> of those words actually is, you need to read the standard for the
> particular language, where such terms are actually defined. In C,
> every expression can be used as a statement, but not the other way
> around. In other programming languages, they are quite different.
> --
> dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
> home: bovenover 215, 1025 jn amsterdam, nederland;http://www.cwi.nl/~dik/


I did some hunting and found a link to a C standard pdf file:
http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

"A statement specifies an action to be performed. Except as indicated,
statements are
executed in sequence." From above document, page 131

"An expression is a sequence of operators and operands that specifies
computation of a
value, or that designates an object or a function, or that generates
side effects, or that
performs a combination thereof." From above document file, page 67


It seems from some of the posts and the document, that you can have
different types of statements, of which an "expression-statement" is
one of them. Jack Klein also shares some good info below too, thanks.
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      12-07-2007
vlsidesign wrote:

> Some of the words used in programming books are foggy to me (maybe I
> should revisit English one day). I looked up some terms in the
> dictionary, which seem to help. In particular, statement and
> expression. Here is what I gathered from a dictionary:
> A statement is an expression in words.
> In math, an expression is a collection of symbols expressing a
> quantity.
>
> In programming, is a statement and expression similar things? How
> would you define an expression in programming, code that evaluates to
> something. Control structures and loops seem to be different and in
> fact contain statements and/or expressions. Thanks for any insight.


As a very broad summary: expressions are things that describe a value;
statements are things that /do/ something [1].

Complications arise because in C some expressions involve statements,
because expressions like F(X) call the function F, which has got
statements inside it [2], and because assignment `L = R`, one of the
two definitive "do somethings", is syntactically an expression, and
because any C expression turns into a statement when you stick a
semicolon at the end, which can give you statements that don't do
anything, like `17;` or `1 + 2`. (The other "do something" is to
produce output/read input, which in C is done by magic system-provided
functions, giving us expressions that "do" things ...)

There's a syntactic distinction between statements and expressions [3],
but that only turns out to be interesting when its inconvenient.

[1] In most programming languages. There are other uses for "statement"
that have it /assert/ things, but I'll quietly pass over them.

[2] C's ancestor BCPL allowed embedding statements directly in expressions
using the VALOF and RESULTIS constructs, but this dead handy syntax
evaporated sometime during C's evolution.

[3] In C. Some languages don't make the distinction in the syntax; everything
(including loops and declarations) is an expression {4}. There is no
mangling of distinctions so bizarre that every language designer
avoids it.

--
Chris "{4} *cough* Spice" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

 
Reply With Quote
 
vlsidesign
Guest
Posts: n/a
 
      12-07-2007
On Dec 7, 3:10 am, Chris Dollin <(E-Mail Removed)> wrote:
> vlsidesign wrote:
> > Some of the words used in programming books are foggy to me (maybe I
> > should revisit English one day). I looked up some terms in the
> > dictionary, which seem to help. In particular, statement and
> > expression.

<snip>
>
> As a very broad summary: expressions are things that describe a value;
> statements are things that /do/ something [1].
>
> Complications arise because in C some expressions involve statements,
> because expressions like F(X) call the function F, which has got
> statements inside it [2], and because assignment `L = R`, one of the
> two definitive "do somethings", is syntactically an expression, and
> because any C expression turns into a statement when you stick a
> semicolon at the end, which can give you statements that don't do
> anything, like `17;` or `1 + 2`. (The other "do something" is to
> produce output/read input, which in C is done by magic system-provided
> functions, giving us expressions that "do" things ...)
>
> There's a syntactic distinction between statements and expressions [3],
> but that only turns out to be interesting when its inconvenient.

<snip>
> --
> Chris "{4} *cough* Spice" Dollin
>
> Hewlett-Packard Limited registered office: Cain Road, Bracknell,
> registered no: 690597 England Berks RG12 1HN


Good stuff, thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments