I have three pointers, *player1, *player2 and *currentPlayer.
The pointer *currentPlayer will always be pointing to either *player1 or *player2. To switch between the two, I’ve been doing the following:
if (currentPlayer == player1) {
currentPlayer = player2;
}
else {
currentPlayer = player1;
}
My question is, is there a simpler, more elegant way to swap between these two pointers?
No, conceptually there’s no simpler way.
Syntactically the ternary operator is a little shorter: