No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

L'opérateur ternaire

Le terme "opérateur conditionnel" n'est pas le plus approprié car il ne s'agit pas d'un signe unique mais bien de la combinaison de deux symboles (? et :).
Nous retrouvons le plus souvent l'opérateur conditionnel sous le terme d'opérateur ternaire, ce qui signifie qu'il prend en compte trois parties de codes séparées par ? et :.
Nous retrouvons aussi parfois l'expression opérateur conditionnel ternaire.

Syntaxe

  1. //opérateur ternaire
  2. <condition> ? <expression_V> : <expression_F>
  3. //syntaxe correspondante
  4. else

Exemples

  1. int i;
  2. //exemple:
  3. int i = a>b ? a : b;
  4. //code identique:
  5. if(a>b){
  6. i = a;
  7. }else{
  8. i = b;
  9. }

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 20/07/2006, last modified the 10/01/2023
Source of the printed document:https://www.gaudry.be/en/programmation-operateur-conditionnel.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.