Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




4.8. The Conditional Operator

The ?: operator is just like an if .. else statement except that because it is an operator you can use it within expressions.

Blah, blah, here's an example:

Example 4-6. apples.c

#include <stdio.h>

  apples = 6;

  printf("I have %d apple%s\n", apples, (apples == 1) ? "" : "s");

  return 0;

?: is a ternary operator in that it takes three values, this is the only ternary operator C has.

  Published under the terms of the GNU General Public License Design by Interspire