-1
int valorNo = (p->left == NULL && p->right == NULL) ? p->key : 0;
I saw it in an answer here in the stack and I have no idea how it works, much less how to "read" it.
-1
int valorNo = (p->left == NULL && p->right == NULL) ? p->key : 0;
I saw it in an answer here in the stack and I have no idea how it works, much less how to "read" it.
1
That’s a ternary operator. Basically, it’s the same thing as doing:
if (p->left == NULL && p->right == NULL)
{
int valorNo = p->key;
}
else
{
int valorNo = 0;
}
Being structured as follows:
(CONDIÇÃO) ? OPERAÇÃO VERDADEIRA : OPERAÇÃO FALSA;
It’s a simplified way to create conditions in the code.
Browser other questions tagged c operators logical-operator
You are not signed in. Login or sign up in order to post.
What’s that? There’s a lot of stuff in there.
– Maniero
@Matheus, as I understand it, is the ternary operator: Expression of test ? Executed expression_se_true : Executed expression_se_false; Being well explained here.
– pss1suporte