Learn C Programming

Lesson 4 of 7 · Decisions

Module 5 · Decisions

The Ternary Operator, and Conditions Worth Naming

Free with an accountReading

Zara wrote the gym's door message as one line of code. It had three question marks, three colons and three conditions, and it worked.

Sign in to read

This lesson is free, with an account

An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.

What is inside The Ternary Operator, and Conditions Worth Naming

  1. The ternary is an expression, so it has a value
  2. A value, never an effect
  3. The one idiomatic use: a choice inside printf
  4. No nesting: name the condition instead
  5. The type of a ternary comes from both arms