General prototype: exp1?exp2:exp3
Ternary operator has a return type of exp2. It is necessary for exp3 to have same return type as exp2 or at least have an implicit conversion. Otherwise it will throw error
In the below program, I am getting an error in CodeBlocks as expected because of exp3 being int and exp2 being char*. Bjut when I am replacing 1 with 0, it is printing 0..
0 is also an int value.I am not able to understand.
#include <iostream>
using namespace std;
int main()
{
int test = 0;
cout << test ? "A String" : 1;
return 0;
}