Why can I use constants as statements in C?

Each of those statements are expressions that evaluate to a value, which is then discarded.
Compare it to if you called a function that returned an int, a char or a float, without using the return value. That’s also an expression that evaluates to a value.

It is not uncommon to have functions that return values that the caller may or may not be interested in, like for example where printf("%d", 9001) returns the number of characters printed. A caller can use the number returned, or they can just ignore it.

If the compiler complained whenever you ignored a return value, you’d have a very noisy build log. Some compilers however diagnose (if sufficient warning flags are enabled) such pointless side-effect-less uses of literals and variables.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)