Possible Duplicate:
What does '?' do in C++?
xo = ((temp.npieces%2)==1)? 1 : 2;
I can't figure out what this means in it's entirety.
xo is an integer (I think simply determining the difference between a naught and a cross)
temp is an instance of position which stores information about a naughts and crosses board (positions on the board of the naughts and crosses, the state of the game (i.e. whether it has been won, lost, or is undecided), and the number of pieces placed so far upon the board
npieces stores the number of pieces placed so far
%2 is obviously determining the remainder of npieces divided by 2, in order to determine whether this is odd or even, and thus whether naughts or crosses plays next
It's the piece at the end that confuses me, the ? 1 : 2
bit, I'm sure I've seen this or things like this before, but I'm afraid I'm not sure what this does. I know this is likely pretty basic stuff, but I was quite ill in my first year of University (I'm in my second year now) and missed odd fragments so I have irritatingly random, often embarassing, gaps in my knowledge.
(This is part of a mass of code for an assignment I'm working on - trying to make sense of a few hundred lines of code, this included. As this is an assignment, I am more than happy not to be told exactly what this line means - and indeed just to be pointed in the direction of a resource that explains ? 1 : 2
so that I can work it out for myself. Either an online resource, or a larger chapter in any textbook available in Safari Books Online would be very helpful, or, of course, a very brief explanation here.)
Thanks.
And my apologies for the un-specific question title, without knowing what the unfamiliar code does or is called, I couldn't think of a better way to phrase it.