(compiling)

CIS241

System-Level Programming and Utilities

C Conditionals and Operations

Erik Fredericks, frederer@gvsu.edu
Fall 2025

Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers

CIS241 | Fredericks | F25 | 30-c-conditionals-operations

Basic operators:

  • Assignment: int x = 7;
  • Arithmetic:
    • Basics: +, -, /, *
    • Modulo: % (Remainder)
    • Modified assignment (do op and store):
      • +=, -=, *=, /=, %=
    • Increment / decrement: ++, --
CIS241 | Fredericks | F25 | 30-c-conditionals-operations

Boolean operators

  • Comparison: ==, !=, >, <, >=, <=`

  • Boolean operations:

    • Not: !
    • And: &&
    • Or: ||
  • Note: These are different than Boolean operators:

    • Not (inverse): ~
    • Bitwise and: &
    • Bitwise or: |
    • Bitwise xor: ^
.

Control statements

if (expr)
{
    statement1;
}
else if (expr2)
{
    statement2;
}
else
{
    statement3;
}

// single line statements don't need braces
if (expr3) statement;
.

Ternary operator

expression ? expression1 : expression2

  • if expression is true, replace with expression1
    else, replace with expression2
CIS241 | Fredericks | F25 | 30-c-conditionals-operations
(c operations)

Order of operations

https://en.cppreference.com/w/c/language/operator_precedence

CIS241 | Fredericks | F25 | 30-c-conditionals-operations