I have recently started programming in C and was wondering about a more concise way to write a simple function that returns 1 or -1 depending on the equality of two int values. What I wrote:
int valueCompare(int i, int j) {
if (i != j) {
return -1;
}
else {
return 1;
}
}
It's readable but seems inefficient. I have seen return statements that utilizes a colon and question mark however am not familiar with that style. Does anyone have any recommendations on how to write a more efficient function for this without a loss of readability?