Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Definition of expression and statement.

Reply
Thread Tools

Definition of expression and statement.

 
 
dspfun
Guest
Posts: n/a
 
      12-29-2007
Hi!

The words "expression" and "statement" are often used in C99 and C-
textbooks, however, I am not sure of the clear defintion of these
words with respect to C.

Can somebody provide a sharp defintion of "expression" and
"statement"? What is the difference between an expression and a
statement?

This is what I have found (textbooks and own conclusions), please
correct if/where wrong.

-------------------------------------------------
An expression is:
An expression contains data or no data.
Every expression has a type and, if the type is not a void, a value.
An expression can contain zero or more operands, and zero or more
operators.
The simplest expressions consists of a single constant, a variable or
a function call.
An expression can contain an assignment.
An expression never contains a semicolon.
Expressions can be joined with other expressions to form more complex
expressions.
Expressions can serve as operands.
A statement will become an expression if the semicolon is removed
(not true for block statements though).
The values of expressions that starts immediately after a semicolon
and ends immediately before next semicolon are always discarded.

Examples:
4 * 512 //Type: int. Value: 2048.
printf("An example!\n) //Type: int Value: Whatever is returned from
printf.
1.0 + sin(x) //Type: double Value: Whatever is the result of the
expression.
srand((unsigned)time(NULL)) //Type: void. Value: None.
(int*)malloc(sizeof(int)) //Type: int*. Value: The address returned
by malloc.
1++ //Type: int. Value: 2, right?
a++ //Type: Depends on a. Value: One more than a.
x = 5 //Type: depends on the type of variable x, right? Value: 5.
2 * 32767 //Type: depends on INT_MAX, right? Value: 65534
Question: what is the type of the expression above?
a //Type: Depends on a. Value: Depends on a.
1 //Type: int. Value: 1
f() //Type: depends on return type of f(). Value: Depends on what
f() returns.

Right?

In the expressions above the values of the expressions are "thrown
away", right?

Any more examples of expressions which are not the same/variants of
above examples?

-------------------------------------------------

A statement is:
Anything separated by semicolons, unless it's a declaration or an
expression in a for statement.
Statements specify an action to be performed, such as an operation or
function call.
Statements are program constructs followed by a semicolon.
An expression that is executed is a statement, right?
Statements do not have a value or a type.
A statement specifies an action to be performed, such as an
arithmetic operation of a function call.
Everey statement that is not a block is terminated by a semicolon.
A statement is always "atomic", i.e., a statement cannot be broken
down into "sub" statements.
The following are statements:
Assignment(=)
Compound ({...})
break
continue
goto
label
if
do, while and for
return
switch

Examples of statements:
All the above expressions will become statements when a semicolon is
added to the expression.

Question: Is it possible to have a statement with a semicolon, which
will not become an expression
when the semicolon is removed?

-------------------------------------------------
Also,

What is the defintion of an expression statement, and how is it
different from a statement and an expression?
Is it just an expression followed by a semicolon.

What is the definition of a block statement?
Is it just one or more statements within curly braces?

BRs!
 
Reply With Quote
 
 
 
 
osmium
Guest
Posts: n/a
 
      12-29-2007
"dspfun" wrote:

> The words "expression" and "statement" are often used in C99 and C-
> textbooks, however, I am not sure of the clear defintion of these
> words with respect to C.
>
> Can somebody provide a sharp defintion of "expression" and
> "statement"? What is the difference between an expression and a
> statement?


I think the only really clear definition comes from a study of the BNF of
the language. (BNF - Backus Normal From/ Backus Naur Form.) Have you
tried Wikipedia?


 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      12-29-2007
dspfun wrote:
> Hi!
>
> The words "expression" and "statement" are often used in C99 and C-
> textbooks, however, I am not sure of the clear defintion of these
> words with respect to C.
>
> Can somebody provide a sharp defintion of "expression" and
> "statement"? What is the difference between an expression and a
> statement?


Section 6.5p1 says:
"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."


Section 6.8p2 says:
"A _statement_ specifies an action to be performed. ..."

The '_' characters around a word indicate that it was italicized in the
original text. That is the standard's way of indicating that these
clauses count as definitions of those terms.

> This is what I have found (textbooks and own conclusions), please
> correct if/where wrong.


Note: I've only corrected you where wrong; I've cut out everything you
wrote in which I found no error (which is not to say that there were no
errors, only that I didn't find them).

....
> An expression never contains a semicolon.


Technically incorrect: c = ';' is an expression. However, expressions
will never contain a semicolon as a token. In that expression, ';' is a
token, but the semicolon character itself is not.

....
> A statement will become an expression if the semicolon is removed
> (not true for block statements though).


This true for expression statements, but not necessarily for other
kinds. Example:

return;

....
> 1++ //Type: int. Value: 2, right?


The left operand of ++ must be an modifiable lvalue. It cannot be an
integer literal.


> a++ //Type: Depends on a. Value: One more than a.


The value of that expression is the value of a before it was
incremented. Note that if 'a' is already at it's maximum, the behavior
of that expression is undefined unless a has an unsigned type.

....
> A statement is:
> Anything separated by semicolons, unless it's a declaration or an
> expression in a for statement.


Statements are not separated by semicolons. Statements include the
semicolon. Also, note that a compound statement is terminated by a '}',
not a semicolon. Finally, note that declarations are also terminated by
semicolons.

....
> Statements are program constructs followed by a semicolon.


Not in the case of compound statements.

....
> An expression that is executed is a statement, right?


No. The three expressions in a for(a; b; c) construct are executed, but
none of them are statements in themselves.

> ... A statement is always "atomic", i.e., a statement cannot be broken
> down into "sub" statements.


Not true for compound, selection, or iteration statements. Each of those
contain sub-statements.

> Question: Is it possible to have a statement with a semicolon, which
> will not become an expression
> when the semicolon is removed?


return;

> What is the defintion of an expression statement, and how is it
> different from a statement and an expression?


An expression statement is a particular kind of statement. There are
many other kinds. An expression statement contains an expression; it is
not itself an expression.

> Is it just an expression followed by a semicolon.


Yes.

> What is the definition of a block statement?
> Is it just one or more statements within curly braces?


Yes.
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      12-29-2007
On Sat, 29 Dec 2007 16:40:04 +0000, James Kuyper wrote:
> dspfun wrote:
>> An expression never contains a semicolon.

>
> Technically incorrect: c = ';' is an expression. However, expressions
> will never contain a semicolon as a token. In that expression, ';' is a
> token, but the semicolon character itself is not.


Semicolons can occur in declarations nested within expressions.

(struct S { int member; }) { 0 }

The above is a perfectly valid expression of type struct S.
 
Reply With Quote
 
manisha
Guest
Posts: n/a
 
      12-29-2007
On Dec 30, 1:53*am, dspfun <(E-Mail Removed)> wrote:
> Hi!
>
> The words "expression" and "statement" are often used in C99 and C-
> textbooks, however, I am not sure of the clear defintion of these
> words with respect to C.
>
> Can somebody provide a sharp defintion of "expression" and
> "statement"? What is the difference between an expression and a
> statement?
>
> This is what I have found (textbooks and own conclusions), please
> correct if/where wrong.
>
> -------------------------------------------------
> An expression is:
> *An expression contains data or no data.
> *Every expression has a type and, if the type is not a void, a value.
> *An expression can contain zero or more operands, and zero or more
> operators.
> *The simplest expressions consists of a single constant, a variable or
> a function call.
> *An expression can contain an assignment.
> *An expression never contains a semicolon.
> *Expressions can be joined with other expressions to form more complex
> expressions.
> *Expressions can serve as operands.
> *A statement will become an expression if the semicolon is removed
> (not true for block statements though).
> *The values of expressions that starts immediately after a semicolon
> and ends immediately before next semicolon are always discarded.
>
> Examples:
> *4 * 512 * * * * * * * * * * * *//Type: int. * *Value: 2048.
> *printf("An example!\n) * *//Type: int * * Value: Whatever is returned from
> printf.
> *1.0 + sin(x) * * * * * //Type: double *Value: Whatever is the result of the
> expression.
> *srand((unsigned)time(NULL)) * *//Type: void. * Value: None.
> *(int*)malloc(sizeof(int)) * * *//Type: int*. * Value: The address returned
> by malloc.
> *1++ * * * * * * * * * *//Type: int. * *Value: 2, right?
> *a++ * * * * * * * * * *//Type: Depends on a. Value: One more than a.
> *x = 5 * * * * * * * * *//Type: depends on the type of variable x, right? Value: 5.
> *2 * 32767 * * * * * * * * * * *//Type: depends on INT_MAX, right? Value: 65534
> *Question: what is the type of the expression above?
> *a * * * * * * * * * * *//Type: Depends on a. Value: Depends on a.
> *1 * * * * * * * * * * *//Type: int. * * Value: 1
> *f() * * * * * * * * * *//Type: depends on return type of f(). Value: Depends on what
> f() returns.
>
> Right?
>
> In the expressions above the values of the expressions are "thrown
> away", right?
>
> Any more examples of expressions which are not the same/variants of
> above examples?
>
> -------------------------------------------------
>
> A statement is:
> *Anything separated by semicolons, unless it's a declaration or an
> expression in a for statement.
> *Statements specify an action to be performed, such as an operation or
> function call.
> *Statements are program constructs followed by a semicolon.
> *An expression that is executed is a statement, right?
> *Statements do not have a value or a type.
> *A statement specifies an action to be performed, such as an
> arithmetic operation of a function call.
> *Everey statement that is not a block is terminated by a semicolon.
> *A statement is always "atomic", i.e., a statement cannot be broken
> down into "sub" statements.
> The following are statements:
> *Assignment(=)
> *Compound ({...})
> *break
> *continue
> *goto
> *label
> *if
> *do, while and for
> *return
> *switch
>
> Examples of statements:
> *All the above expressions will become statements when a semicolon is
> added to the expression.
>
> Question: Is it possible to have a statement with a semicolon, which
> will not become an expression
> when the semicolon is removed?
>
> -------------------------------------------------
> Also,
>
> What is the defintion of an expression statement, and how is it
> different from a statement and an expression?
> Is it just an expression followed by a semicolon.
>
> What is the definition of a block statement?
> Is it just one or more statements within curly braces?
>
> BRs!


hello,
an expression is a combination of one or more operators, operands and
constants which is arranged according to the precedences of operators
and rules of the corresponding languages, an expression every time
produces a result, expressions are in general of several types such
as..constant expression, integral, float, logical, relational, boolean
and bitwise depending upon the value which is produced by an
expression. On the other hand, a statement may be any instruction
given to the computer it is followed by a semicolon, it may contain
keywords, variables, functions etc. statements are also of different
types for eg. control statements, looping statements, branching
statements, i/o statements, type declaration and etc. When an
expression is followed by a semicolon then such stmt. may be called as
a expression stmt. eg. c=a*b;
A block statement is nothing but a group of statements enclosed within
curly braces sometimes it is also called as compound statement and it
has to be every time placed within two braces, most of the times it is
used in loops and function definitions.
 
Reply With Quote
 
Gordon Burditt
Guest
Posts: n/a
 
      12-29-2007
>The words "expression" and "statement" are often used in C99 and C-
>textbooks, however, I am not sure of the clear defintion of these
>words with respect to C.
>
>Can somebody provide a sharp defintion of "expression" and
>"statement"? What is the difference between an expression and a
>statement?


An expression followed by a semicolon is one type of statement.
It is NOT the only type of statement; there are many others.

>An expression is:
> An expression contains data or no data.


I'm not sure what you mean by this, but the expression:
""
might be considered to be an exception.

Ok.
> Every expression has a type and, if the type is not a void, a value.
> An expression can contain zero or more operands, and zero or more
>operators.

Ok.
> The simplest expressions consists of a single constant, a variable or
>a function call.


I don't think I'd call a function call "simple", especially since the
arguments can get very complicated..

> An expression can contain an assignment.

Ok.
> An expression never contains a semicolon.


c = ';'
is a valid expression. So is:
message = "H;e;l;l;o;;;W;o;r;l;d;\n";

> Expressions can be joined with other expressions to form more complex
>expressions.


Ok, but not to an unlimited extent, as there are type rules.

> Expressions can serve as operands.


Ok.

> A statement will become an expression if the semicolon is removed
>(not true for block statements though).


This is only true for expression statements. The following are not
expressions:
return 5
break
int i
continue
and if, for, do-while, while, switch, etc. statements aren't expressions either.

> The values of expressions that starts immediately after a semicolon
>and ends immediately before next semicolon are always discarded.


This is an expression statement you are describing, and yes, the value
is discarded.

>Examples:
> 4 * 512 //Type: int. Value: 2048.
> printf("An example!\n) //Type: int Value: Whatever is returned from
>printf.
> 1.0 + sin(x) //Type: double Value: Whatever is the result of the
>expression.
> srand((unsigned)time(NULL)) //Type: void. Value: None.
> (int*)malloc(sizeof(int)) //Type: int*. Value: The address returned
>by malloc.
> 1++ //Type: int. Value: 2, right?


Error. 1 is not an lvalue. This should not compile.

> a++ //Type: Depends on a. Value: One more than a.


Incorrect. The value returned by a++ is the original value of a.

> x = 5 //Type: depends on the type of variable x, right? Value: 5.
> 2 * 32767 //Type: depends on INT_MAX, right? Value: 65534


This is signed int multiplied by signed int, so the result is signed int.
The value might be 65534 if it is representable in signed int, which is
not guaranteed (and won't be if int is 16 bits).

> Question: what is the type of the expression above?
> a //Type: Depends on a. Value: Depends on a.
> 1 //Type: int. Value: 1
> f() //Type: depends on return type of f(). Value: Depends on what
>f() returns.
>
>Right?
>
>In the expressions above the values of the expressions are "thrown
>away", right?


Yes, if they are used as expression statements. No, if they are used
as function arguments or part of a larger expression.

>Any more examples of expressions which are not the same/variants of
>above examples?
>
>-------------------------------------------------
>
>A statement is:
> Anything separated by semicolons, unless it's a declaration or an
>expression in a for statement.


This is way too simple and does not account for semicolons in character
constants or quoted string constants or comments. It also doesn't account
for things like:

while(borg(foo++) > 0) { }


> Statements specify an action to be performed, such as an operation or
>function call.


It is debatable whether a null statement (lone semicolon) can be considered
to specify an action. Also a constant as a statement expression doesn't
call for any action:
42;

> Statements are program constructs followed by a semicolon.


Some statements don't have their own semicolon but use one in a
statement that's a part of it, for example:

if (foo) printf("Thou hast committed a foo!\n");

> An expression that is executed is a statement, right?


An expression that is a part of a larger expression is not a statement.
An expression that is never executed is still an expression:

if (0) {
a++;
} else {
b++;
}
a++ and b++ above are both expression statements. The fact that a++ will
never be executed is irrelevant.

> Statements do not have a value or a type.
> A statement specifies an action to be performed, such as an
>arithmetic operation of a function call.


This depends a little on how loose you are with the definition of "action".

> Everey statement that is not a block is terminated by a semicolon.


while (1) { 42; }
is not a block (but contains one) and does not end in a semicolon.

> A statement is always "atomic", i.e., a statement cannot be broken
>down into "sub" statements.


That gets iffy if you consider that a left brace followed by zero or more
statements followed by a right brace is a statement.

>The following are statements:
> Assignment(=)

I think you're looking for "expression statement" here.
An assignment need not be an expression statement or in an expression statement:

for (; foo(a = 3, b = 4, c = 5); ) { bar(); }

> Compound ({...})
> break
> continue
> goto
> label
> if
> do, while and for
> return
> switch
>
>Examples of statements:
> All the above expressions will become statements when a semicolon is
>added to the expression.


Which above expressions? Immediately above I see a list of statements,
not expressions.

An expression followed by a semicolon is an expression statement.

>
>Question: Is it possible to have a statement with a semicolon, which
>will not become an expression
>when the semicolon is removed?


Yes, and you listed some of them above.
break continue goto if do, while and for return switch

>What is the defintion of an expression statement, and how is it
>different from a statement and an expression?
>Is it just an expression followed by a semicolon.


Yes. A sub-expression of an expression is an expression but it is
not an expression statement.

>What is the definition of a block statement?
>Is it just one or more statements within curly braces?

Yes.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-29-2007
James Kuyper <(E-Mail Removed)> writes:
> dspfun wrote:
>> The words "expression" and "statement" are often used in C99 and C-
>> textbooks, however, I am not sure of the clear defintion of these
>> words with respect to C.
>>
>> Can somebody provide a sharp defintion of "expression" and
>> "statement"? What is the difference between an expression and a
>> statement?

[...]
> Note: I've only corrected you where wrong; I've cut out everything you
> wrote in which I found no error (which is not to say that there were
> no errors, only that I didn't find them).

[...]
>
> ...
>> An expression never contains a semicolon.

>
> Technically incorrect: c = ';' is an expression. However, expressions
> will never contain a semicolon as a token. In that expression, ';' is
> a token, but the semicolon character itself is not.


Harald showed an example of an expression containing a semicolon
token. (I probably wouldn't have though of that one myself.)

[...]

>> 1++ //Type: int. Value: 2, right?

>
> The left operand of ++ must be an modifiable lvalue. It cannot be an
> integer literal.


I think a lot of newbie C programmers are so fascinated by the "++"
and "--" operators that they forget that the way to add one to an
expression is simply "... + 1".

[...]

>> What is the defintion of an expression statement, and how is it
>> different from a statement and an expression?

>
> An expression statement is a particular kind of statement. There are
> many other kinds. An expression statement contains an expression; it
> is not itself an expression.
>
>> Is it just an expression followed by a semicolon.

>
> Yes.


According to the grammar, the expression in an expression statement
is optional; thus a null statement
;
is a special case of an expression statement.

I don't know why it was defined this way. I think it would have been
simpler to define the null statement as a separate kind of statement.

>> What is the definition of a block statement?
>> Is it just one or more statements within curly braces?

>
> Yes.


Correction: zero or more statements. Actually, zero or more
"block-items", where a block-item is either a declaration or a
statement. (In C90, all the declarations must precede all the
statements; in C99, they can be mixed.)

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-29-2007
manisha <(E-Mail Removed)> writes:
[...]
> an expression is a combination of one or more operators, operands and
> constants which is arranged according to the precedences of operators
> and rules of the corresponding languages, an expression every time
> produces a result,


An expression of type void produces no result.

> expressions are in general of several types such
> as..constant expression, integral, float, logical, relational, boolean
> and bitwise depending upon the value which is produced by an
> expression.


Expressions can be classified in a number of ways, e.g., by the type
of the expression (int, void, double*, etc.) or by the *kind* of
expression, determined by the top-most operator. Your list mixes
these two kinds of classification.

> On the other hand, a statement may be any instruction
> given to the computer it is followed by a semicolon, it may contain
> keywords, variables, functions etc. statements are also of different
> types for eg. control statements, looping statements, branching
> statements, i/o statements, type declaration and etc.


C has no i/o statements; i/o is done by function calls, which
typically appear in expression statements.

Declarations are not statements. <OT>I think they are in C++.</OT>

> When an
> expression is followed by a semicolon then such stmt. may be called as
> a expression stmt. eg. c=a*b;
> A block statement is nothing but a group of statements enclosed within
> curly braces sometimes it is also called as compound statement and it
> has to be every time placed within two braces, most of the times it is
> used in loops and function definitions.


A block statement can also contain declarations, or it can be empty.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-29-2007
manisha <(E-Mail Removed)> writes:
[...]
> an expression is a combination of one or more operators, operands and
> constants which is arranged according to the precedences of operators
> and rules of the corresponding languages, an expression every time
> produces a result,


An expression of type void produces no result.

> expressions are in general of several types such
> as..constant expression, integral, float, logical, relational, boolean
> and bitwise depending upon the value which is produced by an
> expression.


Expressions can be classified in a number of ways, e.g., by the type
of the expression (int, void, double*, etc.) or by the *kind* of
expression, determined by the top-most operator. Your list mixes
these two kinds of classification.

> On the other hand, a statement may be any instruction
> given to the computer it is followed by a semicolon, it may contain
> keywords, variables, functions etc. statements are also of different
> types for eg. control statements, looping statements, branching
> statements, i/o statements, type declaration and etc.


C has no i/o statements; i/o is done by function calls, which
typically appear in expression statements.

Declarations are not statements. <OT>I think they are in C++.</OT>

> When an
> expression is followed by a semicolon then such stmt. may be called as
> a expression stmt. eg. c=a*b;
> A block statement is nothing but a group of statements enclosed within
> curly braces sometimes it is also called as compound statement and it
> has to be every time placed within two braces, most of the times it is
> used in loops and function definitions.


A block statement can also contain declarations, or it can be empty.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      12-29-2007
dspfun wrote:

> Hi!
>
> The words "expression" and "statement" are often used in C99 and C-
> textbooks, however, I am not sure of the clear defintion of these
> words with respect to C.
>
> Can somebody provide a sharp defintion of "expression" and
> "statement"? What is the difference between an expression and a
> statement?
>
> This is what I have found (textbooks and own conclusions), please
> correct if/where wrong.
>
> -------------------------------------------------
> An expression is:
> An expression contains data or no data.
> Every expression has a type and, if the type is not a void, a value.
> An expression can contain zero or more operands, and zero or more
> operators.
> The simplest expressions consists of a single constant, a variable or
> a function call.
> An expression can contain an assignment.
> An expression never contains a semicolon.

putchar(';') is an expression...
> Expressions can be joined with other expressions to form more complex
> expressions.
> Expressions can serve as operands.
> A statement will become an expression if the semicolon is removed
> (not true for block statements though).

Not true for return statements, either. Or break statements.
The other way round (an expression becomes a statement when a semicolon is
added) is correct.
> The values of expressions that starts immediately after a semicolon
> and ends immediately before next semicolon are always discarded.

True, yet a very complicate way to state that.
Simpler and more accurate: "A statement of the form expression; evaluates
the expression for side effects, and discards its value."
> Examples:
> 4 * 512 //Type: int. Value: 2048.
> printf("An example!\n) //Type: int Value: Whatever is returned from
> printf.
> 1.0 + sin(x) //Type: double Value: Whatever is the result of the
> expression.
> srand((unsigned)time(NULL)) //Type: void. Value: None.
> (int*)malloc(sizeof(int)) //Type: int*. Value: The address returned
> by malloc.
> 1++ //Type: int. Value: 2, right?

No. You can't modify a constant. (You meant 1+1, right?)
> a++ //Type: Depends on a. Value: One more than a. x = 5 //Type:
> depends on the type of variable x, right? Value: 5. 2 * 32767 //Type:
> depends on INT_MAX, right? Value: 65534

The type is int. Whether it works depends on INT_MAX.
Question: what is the type of
> the expression above? a //Type: Depends on a. Value: Depends on a. 1
> //Type: int. Value: 1
> f() //Type: depends on return type of f(). Value: Depends on what
> f() returns.
>
> Right?

Yeah.
> In the expressions above the values of the expressions are "thrown
> away", right?

It depends on where they are.
> Any more examples of expressions which are not the same/variants of
> above examples?

&& || < > ?: etc...

> A statement is:
> Anything separated by semicolons, unless it's a declaration or an
> expression in a for statement.

{} is a statement.
> Statements specify an action to be performed, such as an operation or
> function call.

Not necessarily. ((void)0); is a statement.
> Statements are program constructs followed by a semicolon. An
> expression that is executed is a statement, right? Statements do not
> have a value or a type. A statement specifies an action to be
> performed, such as an
> arithmetic operation of a function call.
> Everey statement that is not a block is terminated by a semicolon. A
> statement is always "atomic", i.e., a statement cannot be broken
> down into "sub" statements.

Wrong.
if (foo) { bar(); baz(); } is a statement, but even bar(); and baz(); are
themselves statements, and so is { bar(); baz(); }.
> The following are statements:
> Assignment(=)

Assignments are expression (though they become statements with a
> Compound ({...})
> break
> continue
> goto
> label
> if
> do, while and for
> return
> switch
>
> Examples of statements:
> All the above expressions will become statements when a semicolon is
> added to the expression.
>
> Question: Is it possible to have a statement with a semicolon, which
> will not become an expression
> when the semicolon is removed?

return 0;
break;
goto lab;
> ------------------------------------------------- Also,
>
> What is the defintion of an expression statement, and how is it
> different from a statement and an expression? Is it just an expression
> followed by a semicolon.

Yes.

> What is the definition of a block statement? Is it just one or more
> statements within curly braces?

Yes, but C99 complicates the rules.
enum {a, b};
int different(void)
{
if (sizeof(enum {b, a}) != sizeof(int))
return a; // a == 1
return b; // which b?
}
In C99 the first two lines after the { form a block, so, unlike in C89,
the b in return b; is 1.

--
Army1987 (Replace "NOSPAM" with "email")
 
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
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments