groups

Link to this snippet:


Download to Code Collector

language: C++
licence: Other

Ternery operator / conditional expression

options: send to code collectorview all nepahwin's snippets

// Syntax :

variable = condition ? value if true : value if false

// Using the ? operator :

int opening_time = (day == WEEKEND) ? 12 : 9;

// Without using the ? operator :

int opening_time;
 
if (day == WEEKEND)
    opening_time = 12;
else
    opening_time = 9;