L
Lynn
Excuse me.
Is the sentence below a statement or a function;
srand(time(NULL));
Is the sentence below a statement or a function;
srand(time(NULL));
Lynn said:Is the sentence below a statement or a function;
srand(time(NULL));
Since srand is a void function, it is a function
call that does not return a value.
C functions are peculiar, in that they include
what are procedures in other languages.
The call of the function is a statement.
Lynn said:Excuse me.
Is the sentence below a statement or a function;
srand(time(NULL));
Peter said:No, that's an expression. At least one more thing
is needed to make it a statement.
WANG Cong said:Yes, it is, according to C99.
6.5
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.
6.8
A statement specifies an action to be performed. Except as indicated,
statements are executed in sequence.
WANG Cong said:Yes, it is, according to C99.
6.5
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.
6.8
A statement specifies an action to be performed. Except as indicated,
statements are executed in sequence.
Excuse me.
Is the sentence below a statement or a function;
srand(time(NULL));
Keith Thompson said:Strictly speaking, a function call is a kind of expression (one of the
9 kinds of postfix-expression), *not* a kind of statement. Given a
function call, you can always create a statement from it by adding a
semicolon, but it's the combination of the function call and the
semicolon that forms a statement. But informally, it's ok to refer to
srand(time(NULL);
as a function call.
Paul Hsieh said:In total, its an expression. So between the two, statement is
closer. In C, functions are called or declared or defined. In the
above case there are two functions being called, but the nested way in
which they are connected (the result of time(NULL) being fed to
srand()) is an expression.
<[email protected]> wrote:
Isn't a function call already an expression? Do you mean turn a function
call into a statement without adding a semicolon?
If so, all I'm coming up
with is putting it in a condition:
if ( func() ) { } // no semicolon needed
Ben Bacarisse said:Yes, typo.
That's what I had in mind.
That and the grossly larger
switch(func()){}
while(bar(),0){}
cover all the bases, I think.
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.