CS 108 — Intro to Computer Science: Study Guide
CS 108 INTRODUCTION TO COMPUTER SCIENCE COMPREHENSIVE STUDY GUIDE
LATEST VERSION
Coding Fundamentals · Algorithm Breakdowns · Worked Examples · Practice
Exam
Page 1 of 15
, CS 108 — Intro to Computer Science: Study Guide
Part 1 — Coding Basics
1.1 Variables and Data Types
A variable is a named storage location whose value can change during program
execution. Every variable has a type that determines what kind of data it can hold
and what operations are valid on it.
• Integer (int) — whole numbers: -3, 0, 42
• Floating-point (float/double) — decimal numbers: 3.14, -0.5
• Character (char) — a single symbol: 'a', '9', '$'
• Boolean (bool) — logical value: true or false
• String (str) — sequence of characters: "hello world"
int age = 20;
double gpa = 3.75;
char grade = 'A';
bool isEnrolled = true;
String name = "Alex";
1.2 Operators
• Arithmetic: + - * / % (modulus returns the remainder)
• Relational: == != < > <= >=
• Logical: && (AND) || (OR) ! (NOT)
• Assignment: = += -= *= /=
1.3 Control Structures
Control structures decide the order in which statements run.
// if / else
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else {
grade = 'C';
}
// for loop
for (int i = 0; i < 5; i++) {
print(i);
}
Page 2 of 15
CS 108 INTRODUCTION TO COMPUTER SCIENCE COMPREHENSIVE STUDY GUIDE
LATEST VERSION
Coding Fundamentals · Algorithm Breakdowns · Worked Examples · Practice
Exam
Page 1 of 15
, CS 108 — Intro to Computer Science: Study Guide
Part 1 — Coding Basics
1.1 Variables and Data Types
A variable is a named storage location whose value can change during program
execution. Every variable has a type that determines what kind of data it can hold
and what operations are valid on it.
• Integer (int) — whole numbers: -3, 0, 42
• Floating-point (float/double) — decimal numbers: 3.14, -0.5
• Character (char) — a single symbol: 'a', '9', '$'
• Boolean (bool) — logical value: true or false
• String (str) — sequence of characters: "hello world"
int age = 20;
double gpa = 3.75;
char grade = 'A';
bool isEnrolled = true;
String name = "Alex";
1.2 Operators
• Arithmetic: + - * / % (modulus returns the remainder)
• Relational: == != < > <= >=
• Logical: && (AND) || (OR) ! (NOT)
• Assignment: = += -= *= /=
1.3 Control Structures
Control structures decide the order in which statements run.
// if / else
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else {
grade = 'C';
}
// for loop
for (int i = 0; i < 5; i++) {
print(i);
}
Page 2 of 15