In the C programming language, it is possible to omit a code block in the case of a single statement, for example:
if(1) exit();
Now, does this only apply to conditionals ? Why is this not valid in the case of functions:
void f(int a) exit();
Syntax. function name(param0) { statements } function name(param0, param1) { statements } function name(param0, param1, /* … , */ paramN) { statements } name. The function name.
When one piece of code invokes or calls a function, it is done by the following syntax: variable = function_name ( args, ...); The function name must match exactly the name of the function in the function prototype. The args are a list of values (or variables containing values) that are "passed" into the function.
The single if statement in C language is used to execute the code if a condition is true. It is also called a one-way selection statement.
The first declares a function f that takes two integer arguments and has a return type of void : void f(int, int); This fragment declares a pointer p1 to a function that takes a pointer to a constant character and returns an integer: int (*p1) (const char*);
It's a feature of C syntax. In BNF, a function definition is something like
FUNC_DEF ::= TYPE IDENTIFIER "(" PARAM_LIST ")" BLOCK
while a statement is
STATEMENT ::= (EXPRESSION | DECLARATION | CONTROL | ) ";" | BLOCK
BLOCK ::= "{" STATEMENT* "}"
(simplifying to allow intermixed declarations and statements, which C++ allows but C doesn't), and an if
statement is
CONDITIONAL ::= "if" "(" EXPRESSION ")" STATEMENT
omitting the else
part for now.
The reason for this is that otherwise, you could write the function
void no_op() {}
as
void no_op();
but the latter syntax is already in use to denote a declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With