topskill.dev
CoursesTracks
All courses/C Programming for BeginnersComparisons and True or False
Making Decisions
1 / 6
← C Programming for Beginners
○What a program actually does○The computer and the operating system○From a C file to a running program○Compiled and interpreted programs○Trace One Tiny C Program○Print the Opening Sign✦Module Quiz
○Your First C Program○Variables and Formatted Output○Arithmetic and Integer Division○Formatting and Numeric Conversion○Calculate a Shop Total✦Module Quiz
○Declare and initialize variables○Label the parts bin○Assign a new value○Update the checkout board○Choose int, double, and char○Write a battery test label○Keep local names and constants clear○Count free kit slots✦Module Quiz
○Match printf placeholders and arguments○Print a radio test slip○Build lines with escapes and multiple calls○Print a clock pickup note○Print percent signs and aligned values○Line up a cleaning report○Evaluate expressions before printing○Divide reflectors among trays✦Module Quiz
●Comparisons and True or False○How if and else Choose a Path○Choose a Ticket Message○Select a Fixed Choice with switch○Choose a Service Desk✦Module Quiz
○For Loops: Repeat a Known Number of Times○Add Daily Contributions○While Loops: Repeat While a Condition Holds○Make a Countdown○Run Once with do while○Label a Two-Row Shelf○Label Tool Drawers✦Module Quiz
○Define and Call a Function○Follow a Function Call and Its Return Value○Return a Square○Declare Before a Function Call○Declare and Convert✦Module Quiz
○Arrays and Zero-Based Indexes○Add Array Elements○Count Array Slots Safely○Average Workshop Ratings○Rows and Columns in Memory○Total a Two-Row Grid✦Module Quiz
○C Strings and the Null Terminator○Count a Label○Compare Complete Strings○Verify a Pickup Code○Visit Each Character○Count a Letter in a Label✦Module Quiz
○Pointers: Addresses and Dereferencing○Update Through a Pointer○Pass an Address to a Function○Swap Two Counts○Array Addresses and Offsets○Total with an In-Bounds Pointer○Null, Validity, and Lifetime○Handle an Optional Pointer✦Module Quiz
○Pass an Array and Its Length○Total Readings in a Function○Change Array Elements Through a Parameter○Update Each Stock Count✦Module Quiz
○Define a Supply Record○Record Thread Supplies○Update a Record Member○Update the Paper Stock○Walk an Array of Records○Total the Flyer Stacks○Pass a Record to a Function○Print a Badge Record✦Module Quiz
○One Value in Shared Storage○Record One Ticket Value○A Tag Tells You What Is Stored○Read a Tagged Repair Ticket○Compare Union and Struct Storage○Choose the Right Storage✦Module Quiz
○Read Bits with AND○Check an Equipment Flag○Turn a Flag On with OR○Mark a Kit Ready○Toggle and Clear Individual Flags○Toggle a Warning Flag○Move a Bit into Position○Build a Position Mask✦Module Quiz
○Include the Right Header○Measure a Label with strlen○Guard a Macro Default○Set a Fallback Badge Limit○Include Code Only for Debug Builds○Show an Inventory Diagnostic When Enabled○Parenthesize a Simple Macro○Keep a Macro Calculation Grouped✦Module Quiz
○Name a Status with enum○Confirm an Application Status○Alias a Record Type with typedef○Initialize a Ribbon Record✦Module Quiz
○Where the storage comes from○Request and Release an Array○Store Three Repair Counts○Start Allocated Counters at Zero○Start Station Counters at Zero○Allocate and Release Records○Allocate the parts report✦Module Quiz
○Print a Formatted Label○Print the carving sign○Print Characters with putchar○Build a two-letter mark○Format into a Bounded Buffer○Prepare the shelf label○Write a Line to stdout with fputs○Post the ready notice○Input and Diagnostics in a Local Terminal✦Module Quiz

Comparisons and True or False

Check the room capacity

So far, expressions have calculated counts and measurements. A comparison calculates an answer to a yes-or-no question. A room with 12 attendees and 15 spaces still has room; a full room does not.

OperatorQuestion
<Is the left value less than the right?
<=Is it less than or equal to the right?
>Is it greater than the right?
>=Is it greater than or equal to the right?
==Are the values equal?
!=Are the values different?

Comparisons produce an int: 1 for true or 0 for false. This is a Boolean result, meaning a true/false answer. In a C condition, zero counts as false and any nonzero value counts as true; you do not need a separate Boolean type for these examples.

c
#include <stdio.h>

int main(void) {
    int attendees = 12;
    int capacity = 15;
    printf("Space: %d\n", attendees < capacity);
    printf("Full: %d\n", attendees == capacity);
    printf("Valid: %d\n", attendees > 0 && attendees <= capacity);
    return 0;
}

Run the example. 12 < 15 gives 1; 12 == 15 gives 0. The final expression combines two comparisons with &&, meaning both must be true. Twelve is greater than zero and no greater than the capacity, so Valid is 1.

|| means at least one condition is true. ! reverses a truth value: !0 is 1, and applying ! to any nonzero value gives 0. Like comparisons, these logical operators produce 0 or 1. Do not confuse == with =: the first compares; the second assigns a value.

Stop when the answer is known

&& checks its left operand first. If that is false, it skips the right operand. For example, divisor != 0 && total / divisor > 2 skips the division when divisor is zero. This is called short-circuit evaluation. || skips its right operand when its left operand is already true.

If the attendee count were 15, Space would be 0, Full would be 1, and Valid would still be 1. These boundary values help check whether you chose < or <= deliberately.