C++ Basics - Terminology Reference

This lesson provides a comprehensive reference of all the key C++ terminology you'll encounter throughout Chapter 1. Think of it as your programming vocabulary guide - these are the essential terms every C++ programmer needs to know.

How to Use This Reference

Don't memorize everything now! This lesson is designed to be a reference you come back to as needed:

  • First time through: Read quickly to get familiar with the terms
  • During other lessons: Return here when you encounter unfamiliar terminology
  • When stuck: Use this as a quick lookup guide
  • Before quizzes: Review relevant sections to refresh your memory

💡 Tip: Bookmark this page! You'll find yourself referring back to these definitions as you progress through the course.

Program Structure & Execution

Term Definition Example
Program A set of instructions that tells the computer what to do A complete C++ application
Statement A single instruction that tells the computer to perform some action, usually ends with a semicolon int x = 5;
Function A named group of statements that perform a specific task main(), calculateArea()
main() function The special function where program execution begins; every C++ program must have one int main() { return 0; }
Program entry point The main() function where program execution starts Every program needs exactly one main
Translation unit Single source file plus all included headers after preprocessing main.cpp + all headers = one unit
Source file File containing C++ code that will be compiled Files with .cpp extension
Preprocessor A tool that processes directives (like #include) before compilation Handles
#include <iostream>
Header file A file containing declarations that can be included in programs iostream, string
#include Preprocessor directive that includes library functionality #include <iostream>
return 0 Statement that tells the computer the program finished successfully End of main function
Program termination How C++ programs end execution with return codes return 0 means success

Compilation Process

Term Definition Example
Compilation The process of converting source code into executable program Converting .cpp to .exe
Compiler Tool that translates C++ code into machine language g++, MSVC, clang
Preprocessing First phase handling #directives before actual compilation #include inserts file contents
Object file Compiled code not yet linked into final executable .o or .obj files
Linking Combining object files and libraries into executable Creates final .exe program
Executable Final program file that can run on the operating system .exe on Windows, no extension on Linux

Data Storage & Variables

Term Definition Example
Object A piece of memory that can store values Any variable in memory
Variable A named object that gives us a way to refer to stored data int age;
Data type Defines what kind of data can be stored int, double, char
Declaration Tells the compiler about a variable's type and name int age;
Definition Actually creates the variable and allocates memory Same as declaration in C++
Initialization Giving a variable its first value when it's created int age = 25;
Assignment Storing a new value in an existing variable using the = operator age = 26;

Data Types

Term Definition Range/Usage
int Data type for whole numbers -2,147,483,648 to 2,147,483,647
double Data type for high-precision decimal numbers 15-16 digits precision
char Data type for single characters, enclosed in single quotes 'A', '5', ' '
bool Data type for true/false values true or false
string Data type for text of any length, requires #include <string> "Hello World!"
float Data type for decimal numbers with less precision than double 6-7 digits precision
short Data type for smaller integers -32,768 to 32,767
long Data type for larger integers Platform dependent
Precision The number of significant digits a data type can accurately store float: 6-7 digits, double: 15-16 digits
Overflow When a value becomes too large for a data type to store, causing unpredictable behavior int max + 1 wraps to negative number
Underflow When a floating-point value becomes too small to represent accurately Very small numbers become zero

Understanding Precision

Precision refers to how many significant digits a floating-point number can store accurately. This is crucial when working with decimal numbers:

  • float precision (6-7 digits): Can accurately represent numbers like 3.141592 but may lose accuracy with 3.1415926535 (rounds to 3.141593)
  • double precision (15-16 digits): Can accurately represent 3.141592653589793 but eventually rounds very long numbers
  • Why it matters: Financial calculations, scientific data, and precise measurements require appropriate precision to avoid rounding errors
  • Example: Storing 1.23456789 in a float might actually store 1.234568 due to precision limits

Rule of thumb: Use double for most decimal calculations unless memory is extremely limited, then consider float.

Understanding Overflow

Overflow occurs when you try to store a value that's too large (or too small) for a data type to handle. This can lead to unexpected and dangerous behavior:

  • Integer overflow: When an int exceeds 2,147,483,647, it often wraps around to -2,147,483,648 (like an odometer rolling over)
  • Floating-point overflow: When a float or double becomes too large, it may become "infinity" or produce unpredictable results
  • Underflow: When floating-point numbers become too small to represent accurately, they may become zero (gradual underflow)
  • Why it's dangerous: Programs may crash, produce wrong calculations, or create security vulnerabilities
  • Example: Adding 1 to the maximum int value: 2147483647 + 1 might become -2147483648
  • Real-world impact: Financial software calculating wrong amounts, game scores becoming negative, scientific simulations producing invalid data

Prevention strategies:

  • Choose appropriately sized data types for your expected values
  • Use long or long long for larger integers when needed
  • Check for potential overflow before performing calculations
  • Be especially careful with user input that could cause overflow

Values & Operations

Term Definition Example
Literal A fixed value written directly in code that never changes 5, 3.14, "hello"
Integer literal Whole numbers written directly in code 5, -3, 0
Floating-point literal Decimal numbers written directly in code 3.14159, 0.5
String literal Text enclosed in double quotes "Hello World!"
Operator A symbol that performs an operation on values +, -, *, /, =
Operand The values that operators work with In 5 + 3, both 5 and 3
Expression A combination of values, variables, and operators that produces a result x + y * 2
Evaluation The process of calculating an expression's result 2 + 3 * 4 becomes 14
Precedence Rules determining which operations are performed first in expressions * before +

Common Operators

Term Symbol Description Example
Assignment operator = Assigns a value to a variable x = 5;
Addition + Mathematical addition 5 + 3
Subtraction - Mathematical subtraction 10 - 4
Multiplication * Mathematical multiplication 6 * 7
Division / Mathematical division 15 / 3
Output operator << Sends values to std::cout cout << "Hello";
Input operator >> Reads values from std::cin cin >> age;

Input & Output

Term Definition Usage
iostream Library that provides input and output functionality #include <iostream>
std::cout Console output stream for displaying text on screen std::cout << "Hello";
std::cin Console input stream for reading data from keyboard std::cin >> age;
std::endl End line manipulator that creates a new line and flushes output buffer cout << "Hi" << endl;
Buffer Temporary storage area for input/output data Internal I/O storage
Chaining Using multiple << or >> operators in sequence cout << "Age: " << age;

Code Documentation & Style

Term Definition Example
Comment Text in code that explains what the code does, ignored by compiler // This is a comment
Single-line comment Comment that spans one line, uses // // Calculate total
Multi-line comment Comment that can span multiple lines, uses /* */ /* This spans multiple lines */
Pseudocode Human-readable blueprint for developing software Plain English program steps
Whitespace Spaces, tabs, and newlines used to format code for readability Spaces between words
Indentation Consistent spacing used to show code structure and nesting 4 spaces or 1 tab
Formatting The visual arrangement of code to improve readability Consistent spacing

Naming & Conventions

Term Definition Example
Identifier A name used to identify variables, functions, etc. studentAge, calculateTotal
Keyword A word reserved by C++ with special meaning, cannot be used as variable names int, return, if, while
camelCase Naming convention where first word is lowercase, subsequent words capitalized studentAge, totalScore
snake_case Naming convention using underscores between words student_age, total_score
Case sensitive C++ distinguishes between uppercase and lowercase letters in names Ageage

Language Syntax Fundamentals

Term Definition Example
Scope resolution :: operator used to access items in specific namespaces std::cout specifies std namespace
Namespace Named region to organize code and prevent naming conflicts std namespace contains standard library
Block Code grouped together with curly braces { statements here }
Nesting Placing blocks inside other blocks if statements inside functions

Initialization Types

Term Syntax Description
Copy initialization int x = 5; Initialization using equals sign
Direct initialization int x(5); Initialization using parentheses
Uniform initialization int x{5}; Modern initialization using braces

Error Prevention & Safety

Term Definition Why It Matters
Undefined behavior When program behavior is unpredictable due to programming errors Can crash programs or produce wrong results
Uninitialized variable A variable declared without an initial value, contains garbage data Causes unpredictable behavior
Garbage value Random data left in memory from previous use Found in uninitialized variables
Compiler warning Non-fatal issue that compiler flags as potentially problematic Often indicates bugs even when code compiles
Runtime error Error that occurs when program is running Division by zero, accessing invalid memory
Compile-time error Error caught during compilation before program runs Syntax errors, type mismatches
Defensive programming Writing code that handles unexpected inputs gracefully Prevents crashes and security issues
Narrowing conversion Converting from a larger data type to a smaller one, potentially losing data Can cause data loss or unexpected values

Understanding Narrowing Conversions

Narrowing conversions occur when you try to convert from a data type that can hold more information to one that can hold less. This can result in data loss and unexpected behavior.

Common Examples:

// Narrowing conversions - potentially dangerous
double price = 19.99;
int dollars = price;        // Loses decimal: becomes 19

int bigNumber = 1000;
char smallValue = bigNumber; // char can only hold -128 to 127, undefined result

long long huge = 3000000000;
int normal = huge;          // int max is ~2.1 billion, data loss occurs

Why Narrowing is Dangerous:

  • Data loss: Decimal portions are truncated when converting from floating-point to integer
  • Value corruption: Large numbers may wrap around or become negative when stored in smaller types
  • Silent errors: These conversions often happen without warning, making bugs hard to find

How Uniform Initialization Helps:

// Uniform initialization prevents narrowing conversions
double price = 19.99;
int dollars{price};         // ❌ Compiler error - prevents data loss!

// Traditional initialization allows narrowing (dangerous)
int dollars = price;        // ⚠️ Compiles but loses data silently

Safe Alternatives:

// Explicit conversion when you intend to truncate
double price = 19.99;
int dollars = static_cast<int>(price);  // Explicit: "I know I'm losing data"

// Use appropriate data types
double totalPrice = 19.99;              // Keep as double for calculations
cout << "Price: $" << totalPrice;      // No conversion needed

// Check ranges before converting
int bigNumber = 1000;
if (bigNumber >= -128 && bigNumber <= 127) {
    char smallValue = static_cast<char>(bigNumber);  // Safe conversion
} else {
    cout << "Value too large for char type!" << endl;
}
📚 Note for Beginners
Some concepts in the examples above (like static_cast, if statements, and range checking) are advanced topics that will be covered in detail in later lessons. For now, focus on understanding that narrowing conversions can cause data loss, and that using uniform initialization {} helps prevent them.

Prevention Strategy:

  • Use uniform initialization {} to catch narrowing conversions at compile time
  • Choose appropriate data types for your expected value ranges
  • Use explicit casts when intentional data loss is acceptable
  • Always validate ranges when converting between types

Memory Organization

Term Definition Usage
Stack Memory region where local variables are stored Automatic cleanup when variables go out of scope
Heap Memory region for dynamic allocation (advanced concept) Used with new/delete (covered later)
Memory address Unique location where data is stored in computer memory Like a house address for data

Essential Symbols

Symbol Name Usage Example
; Semicolon Required at end of most statements int x = 5;
{ } Curly braces Group code together, define code blocks int main() { }
" " Double quotes Enclose string literals "Hello World!"
' ' Single quotes Enclose character literals 'A'
( ) Parentheses Function calls, grouping expressions main(), (x + y)

Program Development Process

Term Definition When Used
Algorithm Step-by-step procedure for solving a problem Before writing code
Testing Process of verifying that a program works correctly with different inputs After writing code
Debugging Process of finding and fixing errors in code When problems occur
Iterative development Approach of starting simple and gradually adding features Throughout development
Code review Examining code for correctness, style, and best practices During development
Refactoring Improving code structure without changing functionality Ongoing maintenance

Development Tools

Term Definition Purpose
IDE Integrated Development Environment - tool for writing/editing code Code editing, debugging, compilation
Text editor Simple tool for writing code without advanced features Basic code creation
Build system Tools that automate compilation of complex projects Managing large projects
Version control System for tracking changes to code over time Collaboration, backup, history

Ready for the Quiz?

Take the quiz to test your knowledge of these fundamental C++ terms. Don't worry if you need to refer back to this guide - that's what it's for!