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
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
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>

int
main()
{
  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