0
I’m having trouble using the ?:
#include <stdio.h>
int main()
{
int num1 = 10;
int num2 = 20;
int resposta;
num1 < num2 ? printf("sim\n") : printf("nao\n");
// O erro acontece aqui ao compilar
num1 < num2 ? resposta = 10 : resposta = -10;
printf("%i\n", resposta);
return 0;
}
The ternary accepts statements when inside
()
:num1 < num2 ? (resposta = 10) : (resposta = -10);
, but as in your case is to make a value assignment, the answer below is the best solution.– Sam