Skip to content
KnowledgeCity

Programming with C: Conditionals and Decision-Making

Use the conditional operator to make concise decisions in C programs.
Preview the first lesson free — get full access to all 3 lessons.
Course: On-Demand
Intermediate Provider Mike McMillan  3 Lessons ·  8m  in Arabic, German, English, Spanish, French, Portuguese, Chinese 

Course Description

Making decisions in code is one of the main features of a programming language, and the primary way to make decisions in C is by using one or the other form of the if statement. Simple decisions can be made with an if-else statement while more complex decisions require an if-else if statement.

When making simple if-else decisions, C provides a concise operator for your use: the conditional operator. In these lessons, we’ll start out reviewing the various if statement forms. Then we’ll discuss how the conditional operator is used to make either-or decisions. Finally, we’ll go over an example of a problem that lends itself to a conditional operator solution.

What You'll Learn

  • Describe the different forms of the if statement in C
  • Make simple decisions using if-else and more complex decisions using if-else if statements
  • Explain how the conditional operator is formed
  • Determine when to use the conditional operator instead of if-else statements
  • Apply the conditional operator to advanced either-or decision problems

Key Takeaways

  • Making decisions in code is one of the main features of a programming language, and in C decisions are primarily made using one or another form of the if statement.
  • Simple decisions can be made with an if-else statement, while more complex decisions require an if-else if statement.
  • C provides the conditional operator as a concise way to make either-or decisions in simple if-else situations.
  • Some problems lend themselves to a conditional operator solution rather than an if-else statement.

Frequently Asked Questions

What does this course cover?

The course reviews the various if statement forms, explains how the conditional operator is used to make either-or decisions, and works through an example of a problem that lends itself to a conditional operator solution.

What will I be able to do after taking this course?

You will be able to describe the if statement forms, explain how the conditional operator is formed, and understand when to use the conditional operator instead of if-else statements.

What lessons are included in this course?

The course includes three lessons: If-Else and If-Else If Statements, The Conditional Operator, and Advanced Conditional Operator Uses.

What skills does this course focus on?

It focuses on conditional statements, conditional expressions, conditional compilation, logical operators, operators in C and C++, and interactive C.

When should I use the conditional operator instead of an if-else statement?

The conditional operator is a concise way to make either-or decisions; the course covers when to use it instead of if-else statements, including a problem that lends itself to a conditional operator solution.