int qempty()
{
return (f == r ? 1 : 0);
}
In the above snippet, what does "?" mean? What can we replace it with?
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 commonly referred to as the conditional operator, and when used like this:
… if the
conditionevaluates totrue, the expression evaluates toresult_if_true, otherwise it evaluates toresult_if_false.It is syntactic sugar, and in this case, it can be replaced with
Note: Some people refer to
?:it as “the ternary operator“, because it is the only ternary operator (i.e. operator that takes three arguments) in the language they are using.