Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

The Ternary Operator

C has an alternative syntax for the if-else conditional, referred to as the ternary (or trinary) operator. The name stems from the fact that there are three parts to using the operator. The basic syntax of it is

(condition) ? true_result :

					false_result;

What is notable about this operator is that it returns one of two values based on a condition. This returned value is normally assigned to a variable or printed. For example, the following will return a value indicating whether a number is even or odd (it uses the modulus operator to see if there's a remainder when the number is divided by 2):

 char even_odd; even_odd = ( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book