3 Replies - 568 Views - Last Post: 16 February 2011 - 09:11 AM Rate Topic: -----

#1 tomdog51  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-November 10

conditional operator

Posted 15 February 2011 - 04:28 PM

How do you write a conditional operator to determine which number
is smaller and which is larger. I can do it with an if /else statement but was told to try it with conditional operator.
Is This A Good Question/Topic? 0
  • +

Replies To: conditional operator

#2 barnwillyb  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 108
  • Joined: 22-May 07

Re: conditional operator

Posted 15 February 2011 - 04:34 PM

http://www.cplusplus...rial/operators/
Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: conditional operator

Posted 16 February 2011 - 05:25 AM

int a = 5, b = 6;
std::cout << (a < b ? "a" : "b") << " is larger";


Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: conditional operator

Posted 16 February 2011 - 09:11 AM

First link in a Google search of conditional operator. It's also known as the ternary operator.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1