• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Aritmethic if.

Hello Again experts...

Could anyone explain to me how to use the "?:" sign in C or C++?

Well... In a book I read that it is an "Aritmethic if". And show an expresion like this.

i > j ? i : j

I think (Not sure) it is used like this

a = i > j ? i : j or a = (j > i ? i : j)

Well... anyway... I'd like some example of how to use it, and a litle detailed explanation on how to use it...

Greetings and thanks.
0
Marsc
Asked:
Marsc
1 Solution
 
chensuCommented:
x ? y : z;

is the same as

if (x)
    y;
else
    z;

So,

a = i > j ? i : j;

is the same as

if (i > j)
    a = i;
else
    a = j;
0
 
KangaRooCommented:
But the result can also be used as lvalue:

 (i > j ? i: j) = a;
0
 
MarscAuthor Commented:
Thanks...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now