#define VALUE_MAX 300
int main() {
if(VALUE_MAX)
printf("The value is %d",VALUE_MAX);
return 0;
}
When I try to compile the above program if(VALUE_MAX)
is showing a warning
conditional expression is constant.
How to solve the above warning?
In your code,
VALUE_MAX
is not a variable, it's a MACRO. MACROs can be considered as a textual replacement at preprocessing time. So,which is translated to
is always TRUE. It is equivalent to
which is having essentially no effect. The code block under the
if
condition will execute unconditionally.EDIT: (Elaboration for better understamding)
An
if
statement is called a selection statement. The syntax of simpleif
statement isbased on the evaluation of
expression
, it is decided whether the followingstatement
(or block) will be executed.In case of your code,
always evaluates to TRUE. In this scenario, the use of
if
statement is meaningless. YOu can get rid of theif
statement altogether.