well , in a rather simple way
an expression is a combination of of literals , variables , operators , functions calls which produces a particular value to be used in any other context
while a statement is an instruction to the computer telling it what to do for instance assigning an expression value to a variable , cause it produces an instructions tells the computer to assign a value to something.
to be more accurate , you can tell if A is a statement or an expression accurately by looking at the context which is been used in
well , in a rather simple way
an expression is a combination of of literals , variables , operators , functions calls which produces a particular value to be used in any other context
while a statement is an instruction to the computer telling it what to do for instance assigning an expression value to a variable , cause it produces an instructions tells the computer to assign a value to something.
to be more accurate , you can tell if A is a statement or an expression accurately by looking at the context which is been used in
It depends on the language in context/question.
The answer to this question is actually in that computer language specification. Every computer language has its own specification/definition of "expression" and "statement". There maybe some languages that do not even define what a statement is (no notion of statements, only expressions)
If you have 1 particular computer language in mind, it may break the concept below
In general:
The evaluation of an expression may do something itself, like calling a function in an expression like:
100 * Call_A_SUB()
Call_A_SUB() is a function returns a value to be multiplied to 100. It may have done something (statements) before returning a final value!!
An expression can be a statement, but some statements aren't expressions. Examples for the former: x++, y = 3, printf ("Hello"); examples for the latter: if, else, while, for, do, switch, break, continue, return
Expressions can only be used as statements if you're using an assignment ("=") operator. Every statement must commit an action of some sort, whether it's modifying a variable or calling a function; so comparison expressions by themselves will do nothing. For instance, the following code is futile:
myvar==5;
You would need to use this within an 'if' statement at the very least:
if (myvar==5) { dosomething(); }
Or within a function:
doanotherthing(myvar==5);
IF, in C and C++, is not a function - it is a statement. There are two parameters... if (expression) statement; The expression is evaluated. If it has logical result true, or arithmentic result not zero, the statement is executed; if not, the statement is not executed. The statement can be a single statement, in which it is terminated with a semi-colon, or it can be a block of statements, in which it is surrounded by braces.
The C and C++ for loop is defined as...for (init-expression; test-expression; loop-expression) loop-statement;The init-expression is executed once.At the top of the loop, test-expression is evaluated. If it is false, control passes to the statement following loop-statement.The loop-statement is executed. It may be one statement, it may be a block of statements, or it may be no statement. If it is no statement, the semi-colon is required.At the bottom of the loop, loop-expression is executed, and then control passes to the test-expression at the top of the loop for another go-around.Each of init-expression, test-expression, and loop-expression may be missing. The semi-colons are required. The formal "forever" loop is for (;;) loop-statement; in which case the only way out is the break statement.Since each of init-expression, test-expression, and loop-expression can have side-effects, sometimes a loop is constructed with no loop-statement, and all processing is done between the parentheses.If test-expression is initially false, loop-expression and loop-statement are never executed. The init-expression is always executed only one time, and test-expression is executed at least one time.At any point during loop-statement, the breakstatement will exit to the statement following loop-statement, and the continue statement will jump to the loop-expression at the bottom of the loop.
The else statement is an optional part of an if statement that is executed if the primary if condition is false.if (condition) true_statementelse false_statement
The semi-colon converts a C++ expression into a statement.
A loop in computer languages is a set of statements that execute repeatedly, based on some criteria.In C and C++, the three looping statements are while, do, and for...while (test-expression) statement;/* statement executes zero or more times, until test-expression is false, test first */do statement while (test-expression);/* statement executes one or more times, until test-expression is false, test last */for (init-expression, test-expression, loop-expression) statement;/* init-expression executed once, at beginning *//* statement executes zero or more times, until test-expression is false, test first *//* loop-expression evaluated at end of each iteration */Often, statement, is a set of statements, such as...while (test-expression) {... statements}
A statement in C is an expression terminated with a semi-colon. That is, a semi-colon turns an expression into a statement.
A statement in C is an expression terminated with a semi-colon. That is, a semi-colon turns an expression into a statement.
It is one of the statements. Its syntax in BNF is the following: statement ::= for_statement for_statement ::= 'for' '(' opt_expression ';' expression ';' expression ')' statement
IF, in C and C++, is not a function - it is a statement. There are two parameters... if (expression) statement; The expression is evaluated. If it has logical result true, or arithmentic result not zero, the statement is executed; if not, the statement is not executed. The statement can be a single statement, in which it is terminated with a semi-colon, or it can be a block of statements, in which it is surrounded by braces.
Only one: expression. Yes, in C expression is one of the statements. Some other statements are: if, do, goto, while, for, switch, break, continue, return, NULL-statement, compound-statement.
The C and C++ for loop is defined as...for (init-expression; test-expression; loop-expression) loop-statement;The init-expression is executed once.At the top of the loop, test-expression is evaluated. If it is false, control passes to the statement following loop-statement.The loop-statement is executed. It may be one statement, it may be a block of statements, or it may be no statement. If it is no statement, the semi-colon is required.At the bottom of the loop, loop-expression is executed, and then control passes to the test-expression at the top of the loop for another go-around.Each of init-expression, test-expression, and loop-expression may be missing. The semi-colons are required. The formal "forever" loop is for (;;) loop-statement; in which case the only way out is the break statement.Since each of init-expression, test-expression, and loop-expression can have side-effects, sometimes a loop is constructed with no loop-statement, and all processing is done between the parentheses.If test-expression is initially false, loop-expression and loop-statement are never executed. The init-expression is always executed only one time, and test-expression is executed at least one time.At any point during loop-statement, the breakstatement will exit to the statement following loop-statement, and the continue statement will jump to the loop-expression at the bottom of the loop.
The comma operator will let you use multiple statements in an expression in C or C++.Strictly speaking, you cannot have a statement inside an expression, for example the following is completely wrong:int n;n = 1 + for (i=0; i
The for loop in C, and C++ and Java, is defined as ...for (init-expression, limit-expression, loop-expression) statement;The init-expression is evaluated once. Then the limit-expression is evaluated. If it is true, the statement is evaluated, which can be a block of statements, or even a null statement, otherwise, control transfers out of the loop. If the statement is executed, then the loop-expression is evaluated, and control transfers back to the limit-expression.As an example, to print the numbers 1 through 10 ...for (int i = 1; i
BNF:statements -> | statement statementsstatement -> block | null_statement | expression_statement | if_statement | while_statement | ...null_statement -> ;expression_statement -> expression ;block -> { declarations statements }declarations -> | declaration declarationsif_statement -> if ( expression )statement
first i would like to tell about if . if is keyword in c language . if is check the condition(expression) .if the expression is non zero value the condition is true .it will the go through the fallowing operations .other wise the condition is failed. if(expression) { } if the expression is >0 ,<0 these statements are execute inside the if statement. if the expression is =0 condition is failed.
The else statement is an optional part of an if statement that is executed if the primary if condition is false.if (condition) true_statementelse false_statement
Syntax:if (expression)statement;[elsestatement;]The expression must evaluate to a boolean value, where zero is false and all non-zero values are true. The statement (including the optional else statement) may be simple or compound, and may include a nested if statement. When the expression evaluates true, the first statement is invoked. If an else statement is provided, it is only executed when the expression evaluates false. After the appropriate statement is invoked, execution passes to the statement that immediately follows the entire if statement.