CS1120 Midterm 2 Theory Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

flashcard set

Earn XP

Description and Tags

Comprehensive vocabulary flashcards covering key C++ concepts from the CS1120 Midterm 2 theory review.

27 Terms

1
New cards

Function

A construct that organizes code into reusable tasks (e.g., calling one via int result = Square(5);).

2
New cards

Pass by Value (int x)

A parameter-passing mechanism where the function gets a copy of the argument, leaving the original variable unchanged.

3
New cards

Pass by Reference (int& x)

A parameter-passing mechanism where the function receives the original variable directly and can modify it.

4
New cards

const vector& v

A parameter declaration specifying that the function reads the vector without copying it (&) and without changing it (const).

5
New cards

Default Parameters

Function parameters assigned fallback values that must be placed as the rightmost parameters (e.g., void Show(int x, int y = 5); is correct; void Show(int x = 5, int y); is wrong).

6
New cards

Function Overloading

Defining multiple functions with the same name but different parameter lists (different numbers or types). Differing only in return type or only in parameter names is not valid.

7
New cards

Header File (.h) vs. Source File (.cpp)

Declarations are placed in .h files and definitions in .cpp files; main.cpp uses #include "functions.h" and never includes the .cpp file.

8
New cards

Scope of a Local Variable

The boundary within which a local variable is accessible, limited strictly to inside the function where it is declared.

9
New cards

2D Array Indexing

Accessing elements in a two-dimensional array using grid[row][col] with 0-based indices (e.g., given int g[2][2] = {{3,5},{7,9}};, g[1][0] evaluates to 7).

10
New cards

v.push_back(x) and v.size()

Basic vector member functions where v.push_back(x) adds an element or object (such as students.push_back(s1);) to the end, and v.size() returns the element count.

11
New cards

Class vs. Object

A class serves as the blueprint, whereas an object is a concrete instance of that class (instantiated via Student s1;).

12
New cards

Constructor

A special member function that initializes an object, sharing the same name as the class, having no return type, and running automatically upon creation (e.g., default: Box b; parameterized: Box b(5);).

13
New cards

Private Data Members

Variables kept private within a class to provide controlled access through public member functions, such as getters to read values and setters to validate and write values.

14
New cards

Member Function Calling Syntax

Invoking a member function on an object using the dot operator (book.Print();) or on a pointer using the arrow operator (ptr->Print();).

15
New cards

Address-of Operator (&x)

An operator that evaluates to the memory address of variable x.

16
New cards

Dereference Operator (*p)

An operator that retrieves the value stored at the memory address pointed to by pointer p.

17
New cards

nullptr

A keyword representing a pointer that points to nothing, which must never be dereferenced.

18
New cards

Dynamic Memory Allocation and Deallocation

Allocating memory dynamically using new and freeing it using delete (e.g., int* p = new int; then delete p;), or using delete[] for dynamically allocated arrays (int* arr = new int[5]; then delete[] arr;).

19
New cards

Memory Leak

Dynamically allocated memory that can no longer be accessed by a program but has not been released.

20
New cards

Dangling Pointer

A pointer pointing to an object whose lifetime has ended (such as after delete). Setting p = nullptr; after deletion is a good practice to prevent it.

21
New cards

cin >> vs. getline()

Input methods where cin >> s stops extracting upon encountering whitespace, while getline(cin, line); reads the entire line including spaces.

22
New cards

File I/O Workflow

The standard sequence for handling files using ifstream (to read) and ofstream (to write): open -> check it opened -> stream data (inFS >> x; or outFS << x;) -> close().

23
New cards

istringstream

A stream class used to read and extract values from an existing string.

24
New cards

ostringstream

A stream class that stores formatted output inside a string, which can be retrieved using .str().

25
New cards

class Dog : public Animal

Inheritance syntax denoting that Dog derives from Animal, meaning Animal is the base class, Dog is the derived class, and Dog can use Animal's public members.

26
New cards

Recursive Function

A function that calls itself, requiring a base case to stop execution and recursive calls that move toward that base case to prevent infinite recursion.

27
New cards

Constructor Execution Order in main()

The deterministic sequence where constructors run in the exact order in which the objects are declared, causing the first declared object's constructor to execute first.