What does following declaration mean in C?
char a = (10,23,21);
While printing the value of “a” with “%u” the output is 21.
gcc is not giving any error.
What’s this kinda declaration and what’s the use of it?
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.
This is a use of the scalar comma operator. The comma operator evaluates each expression on the left side and throws away the return value, finally returning the rightmost value.
In this case, it’s useless; however, if you use it with expressions with side-effects, then it has a real effect.
Example of a semi-“useful” expression (with side-effects):
The first expression (
++a) has a clear side-effect, and it is evaluated first (before thea % 2). The second expression is the expression that is yielded into the assignment.