10.1 Variables, Types & Operators

Key Takeaways

  • A variable is a named storage location; its type constrains what values it can hold and which operations are valid
  • Assignment (=) stores a value; equality (==) compares two values — confusing them is a classic Cyber Test trap
  • Arithmetic (+ − * / %), comparison (< > <= >= == !=), and logical (AND OR NOT) operators combine into expressions evaluated by precedence rules
  • Integer division truncates toward zero in many languages; mixing types can produce unexpected results without an explicit cast
  • Tracing code means updating a mental table of variable names and values after each statement in order
Last updated: July 2026

Programming questions on the USAF Cyber Test (CSAT/ICTL heritage) rarely ask you to write long programs. They ask you to read short snippets, predict values, and spot mistakes. That skill rests on three ideas: variables hold values, types constrain those values, and operators combine them into expressions. Master tracing — walking the code line by line — and most items become mechanical.

Why Variables Matter

A variable is a named box in memory. The name is a label; the box holds a current value that can change as the program runs. Pseudocode style:

SET count TO 0
SET count TO count + 1

After the first line, count is 0. After the second, count is 1. Exams love questions that ask "what is the value of X after these statements?" Your job is to maintain a tiny state table and update it after every assignment.

Naming and Mutability

Names should be unique within a scope (you will see scope again with functions). Reassigning does not create a new box in most beginner models — it overwrites the old value. If x was 5 and you set x to 9, the 5 is gone unless you stored it elsewhere first.

ConceptMeaningExam cue
DeclarationIntroduce the name (and often the type)int n; or n = 0 in Python
InitializationFirst meaningful valueUninitialized use is a bug
AssignmentStore a new valueRight-hand side evaluated first
Read / useExpression looks up current valueOrder of statements matters

Types: What the Box Is Allowed to Hold

A type tells the language (and you) what kind of data lives in the variable. Cyber Test items stay near the primitives:

Type familyTypical valuesNotes
Integer-3, 0, 42Whole numbers; common for counters and array indices
Floating-point3.14, -0.5Approximate real numbers; rounding can surprise
Booleantrue / false (or True / False in Python)Results of comparisons; drive if decisions
Character / string'A', "hello"Text vs sequence of characters — language-dependent

Python flavor: types are attached to values; x = 3 then x = "hi" is allowed. C++ flavor: you declare the type; int x = 3; then assigning a string is a compile-time error. The exam cares more about what value results than about compiler jargon, but knowing that integers and floats behave differently under division is fair game.

Integers vs Floats in Division

In many C-family languages, 7 / 2 with integer operands yields 3 (truncation toward zero), while 7.0 / 2 yields 3.5. In Python 3, / always produces a float (7 / 23.5) and // is floor division (7 // 23). If a stem shows / without clarifying language, look for context clues (integer variables, int, float, or //).


Operators

Arithmetic

OperatorMeaningExample
+Add3 + 47
-Subtract10 - 37
*Multiply6 * 742
/Dividelanguage-dependent
%Modulo (remainder)17 % 52

Modulo is high-yield: n % 2 == 0 tests evenness; n % 10 peels off the last decimal digit.

Comparison (Relational)

Comparisons produce booleans:

  • == equal
  • != not equal
  • <, >, <=, >=

Logical

  • AND (&& in C++, and in Python): true only if both sides true
  • OR (|| / or): true if at least one side true
  • NOT (! / not): flips true/false

Short-circuit evaluation: if the left side of AND is false, the right side may never run. Exam stems usually stay simple, but if a right-hand expression has a side effect (assignment or call), short-circuit can change outcomes.

Assignment vs Equality — The Classic Trap

SymbolRoleWrong use
=Assignment: store RHS into LHSUsing = when you meant "are these equal?"
==Equality test: compare two valuesUsing == when you meant to store

Worked trap (C++-style):

int x = 5;
if (x = 0) { /* body */ }

The condition uses assignment. It sets x to 0, and the value of the assignment expression is 0, which is treated as false — so the body does not run, and afterward x is 0. Candidates who skim as "if x equals 0" miss that x was overwritten.

Python note: if x = 0 is a syntax error; Python forces == in conditions. Stems that mix languages still test the conceptual distinction.

Compound Assignment

x += 2 means x = x + 2. Same pattern for -=, *=, /=, %=. Always evaluate the right-hand expression using the current value of x, then store.

Precedence (Order of Operations)

Rough high-to-low order (simplified):

  1. Parentheses ()
  2. Unary NOT / unary minus
  3. *, /, %
  4. +, -
  5. Comparisons
  6. AND
  7. OR
  8. Assignment

When unsure, parenthesize mentally. 3 + 4 * 2 is 11, not 14.


Worked Tracing Example (Language-Agnostic)

SET a TO 4
SET b TO 10
SET c TO a + b * 2
SET a TO a + 1
SET flag TO (a > 4) AND (c == 24)

State after each line:

Stepabcflag
start
14
2410
341024
451024
551024true

Why c is 24: b * 2 is 20, then a + 20 is 24. Why flag is true: after increment, a > 4 is true and c == 24 is true.

Python / C++ Flavor Side-by-Side

Python:

a = 4
b = 10
c = a + b * 2
a += 1
flag = (a > 4) and (c == 24)

C++:

int a = 4;
int b = 10;
int c = a + b * 2;
a += 1;
bool flag = (a > 4) && (c == 24);

Same final values. The Cyber Test rewards recognizing that shared logic, not memorizing one syntax tree.


Exam Habits

  1. Build a state table; never "eyeball" multi-step snippets.
  2. Circle every = and ask: assignment or equality?
  3. Resolve * / % before + - unless parentheses say otherwise.
  4. Watch integer vs float division when the stem emphasizes whole-number types.
  5. Modulo questions often hide in "remainder" or "even/odd" wording.

Programming fundamentals here feed the next sections: control flow decides whether assignments run, and functions package expressions into reusable units. If you can already update a state table confidently, you are ready for if, loops, and call stacks.

Test Your Knowledge

After these statements, what is the value of result? Assume integer arithmetic with truncation on division: x = 17; y = 5; result = x % y + x / y;

A
B
C
D
Test Your Knowledge

In a C-style condition, which statement best describes if (n = 0)?

A
B
C
D
Test Your Knowledge

What is the value of expr for: expr = 2 + 3 * 4 - 8 / 2; using standard arithmetic precedence and integer division?

A
B
C
D
Test Your Knowledge

Variables a and b start as a = 3 and b = 7. After t = a; a = b; b = t; what are a and b?

A
B
C
D