1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is an array?
Fixed-size, contiguous, ordered collection of same-type variables accessed by index
Why use arrays?
When you need to revisit data multiple times.
What happens if you access an invalid index?
Undefined behavior (C++ does not check bounds)
How does array initialization behave?
No initializer → garbage values.
Fewer initializers → rest filled with zeros.
int arr[] = {1,2,3}; → compiler infers size.
What is decomposition?
Breaking a program into smaller functions.
What is abstraction?
Hiding details, showing only “what it does.”
What is a function prototype?
Declares function’s return type and parameters so it can be called before definition.
Example: double area(double, double);
What is function overloading?
Same function name, different parameter list (number or type).
Procedural vs OOP?
Procedural: function = unit of organization.
OOP: class/object = unit of organization.
What is an array look-up table?
Precomputed results stored in an array, accessed by index.
What is a character array (C-string)?
Array of chars ending with \0. Example: char str[] = "Hi";
Why are arrays passed by reference?
Passing whole arrays by value would copy too much data. Instead, only the starting pointer is passed.
What are void functions?
Functions with no return value.
What is pass-by-value vs. pass-by-reference?
Value = copy passed (safe, but doesn’t affect caller).
Reference = original passed (function can change caller’s variable).
What are common C-string library functions?
strlen(s) → length
*strcpy(dest, src) → copy string
*strncpy(dest, src, n) → safe copy
strcmp(s1, s2) → compare (0 = equal)
strcat(char *dest, const char *src) -> Adds str to end of dest
strchr(const char *str, char c) -> Finds first occurrence of c & returns ptr
User Defined Functions
"Declare" your function by placing the prototype (signature) at the top of your code
"Define" the function
"Call" the function
Formal vs Actual parameters:
Placeholder names that will be used internally to the function to refer to the values passed
Actual values to be passed
Memory organization:
Code usually sits at lower addresses
Global variables/data somewhere after code
Heap: Area of memory that can be allocated and de-allocated during program execution
Stack (our focus): Memory for all information related to each running instance of a function like arguments, local variables, return link
Stacks:
Each time a function is called, the computer allocates memory for that function on the top of the stack and creates a link for where to return
When a function returns/ends, that memory is deallocated