4 Replies - 222 Views - Last Post: 17 January 2013 - 10:51 PM Rate Topic: -----

#1 The_afridi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 12

What does it means in C and wht simplest form of this statement will

Posted 17 January 2013 - 10:39 PM


char opponent = (player == 'W')? 'B' : 'W';




i cannot understand that above statement in c and what will be its simplest form? and what is above statement called in c ? c??
Is This A Good Question/Topic? 0
  • +

Replies To: What does it means in C and wht simplest form of this statement will

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10367
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: What does it means in C and wht simplest form of this statement will

Posted 17 January 2013 - 10:44 PM

It's called the ternary operator, and is evaluated in the following way: (condition) ? true-value : false-value.

So if the player == 'W', then opponent is 'B'. Otherwise, the opponent is 'W'.
Was This Post Helpful? 2
  • +
  • -

#3 The_afridi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 12

Re: What does it means in C and wht simplest form of this statement will

Posted 17 January 2013 - 10:48 PM

ok sir but how it can be converted into if else statment?
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 3988
  • View blog
  • Posts: 12,303
  • Joined: 25-December 09

Re: What does it means in C and wht simplest form of this statement will

Posted 17 January 2013 - 10:48 PM

Quote

and what is above statement called in c ? c??

This is called a ternary operator.

Quote

its simplest form?

To me the simplest form would be an if/else statement.
char opponent;
if(player == 'W')
   opponent = 'B';
else 
   opponent = 'W';



Jim
Was This Post Helpful? 2
  • +
  • -

#5 The_afridi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 12

Re: What does it means in C and wht simplest form of this statement will

Posted 17 January 2013 - 10:51 PM

thank you sir it was very helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1