I'm having trouble with the ternary operator. I want to use it to make the code more elegant because it is a simple thing. But it's like it does not work because it does not update the variable. The following example depicts the problem:
#include <iostream>
using namespace std;
int main()
{
int k=0;
for(int i=0;i<10;i++){
k= (i<5)? k++:k;
}
cout << k << endl;
return 0;
}
What can it be? For the result of the variable k
is shown as 0.