Why does this program below not show any error ?
int main (void) {
"ANGUS";
1;
3.14;
return 0;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.