#define Val_MAX 0
int main() {
if(Val_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,
Val_MAXbeing a#defined value to0is actually (you can check after preprocessing with
gcc -E)which is not of any worth. The Following
printf()will never execute.FWIW, a selection statement like
ifneeds an expression, for which the value evaluation will be expectedly be done at runtime. For a fixed value, a selection statement makes no sense. It's most likely going to end up being an "Always TRUE" or "Always FALSE" case.One Possible solution: [With some actual usage of selection statement]
Make the
Val_MAXa variable, ask for user input for the value, then use it. A pseudo-code will look like