if statement
From cppreference.com
Conditionally executes code.
Used where code needs to be executed only if some condition is true.
Syntax
attr-spec-seq(optional) if ( expression ) statement-true
|
(1) | ||||||||
attr-spec-seq(optional) if ( expression ) statement-true else statement-false
|
(2) | ||||||||
| attr-spec-seq | - | (C23)optional list of attributes, applied to the if statement
|
| expression | - | an expression of any scalar type |
| statement-true | - | any statement (often a compound statement), which is executed if expression compares not equal to 0
|
| statement-false | - | any statement (often a compound statement), which is executed if expression compares equal to 0
|
Explanation
expression must be an expression of any scalar type.
If expression compares not equal to the integer zero, statement-true is executed.
In the form (2), if expression compares equal to the integer zero, statement_false is executed.
|
As with all other selection and iteration statements, the entire if-statement has its own block scope: enum {a, b};
int different(void)
{
if (sizeof(enum {b, a}) != sizeof(int))
return a; // a == 1
return b; // b == 0 in C89, b == 1 in C99
|