Heap Management, Control Flow, Coroutines, and Object-Oriented Programming Flashcards

(50 cards)

1
Q

What is heap fragmentation?

A

Occurs when allocated memory blocks are freed, leaving gaps that may not fit new allocations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are common allocation strategies for heap memory?

A
  • First fit
  • Best fit
  • Next fit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you inspect the stack frame layout?

A

By using printf to display the addresses of parameters and local variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the role of the frame pointer?

A

It is the base of the current function call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of the stack pointer?

A

It indicates the top of the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What tools can be used to inspect compiled binaries?

A
  • objdump (CLI disassembler)
  • Boomerang (GUI decompiler)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Fill in the blank: The stack is used for _______ and function frames.

A

Local vars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Fill in the blank: The heap is used for _______ memory.

A

Dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False: Each process has its own space managed by the OS using page tables.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does a jump do in programming?

A

Moves the program counter (PC) to a new instruction address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List three uses of jumps in programming.

A
  • Control flow (loops, conditions)
  • Error handling
  • Special tricks like coroutines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an unconditional jump in assembly?

A

jmp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are conditional jumps used in assembly?

A
  • jg
  • je
  • etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of the goto statement in C?

A

Transfers control to a labeled statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is one pro and one con of using goto in C?

A
  • Pro: Useful for error handling or cleanup
  • Con: Can lead to spaghetti code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: Dijkstra’s paper states that goto is beneficial for programming.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the goto statement allow for in cleanup operations?

A

Acts like try/catch for low-level cleanup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the example of using goto for cleanup in C?

A

if (!(p = malloc())) goto errexit;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is setjmp() used for?

A

Saves CPU state (registers, stack, etc.) into a jmp_buf.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does longjmp() do?

A

Restores saved state and jumps back to the setjmp call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Fill in the blank: setjmp creates a _______.

22
Q

How does error handling with setjmp/longjmp work?

A

setjmp captures state, longjmp restores it on error.

23
Q

What is the main difference between subroutines and coroutines?

A

Subroutines have one-way calls; coroutines yield back and forth.

24
Q

What happens to the stack when using coroutines?

A

Stack stays intact.

25
What is a risk when using coroutines?
Stack may overflow or behave unpredictably if deeper recursion occurs.
26
When should you use goto?
Quick jump for cleanup only.
27
What is the low-level control transfer mechanism in C?
setjmp/longjmp
28
What do coroutines allow two routines to do?
Take turns executing.
29
What is a crucial role in coroutines?
The stack.
30
What is the first OOP language?
Simula 1967
31
Which programming language did C++ evolve from?
C
32
Who created C++?
Bjarne Stroustrup
33
What is a key feature introduced in C++ compared to C?
Classes
34
What does a precompiler do?
Translates annotated/extended code into standard C
35
Give an example of a precompiler.
Oracle Pro*C
36
What is a notable difference between C and C++?
* C++ adds classes * Exceptions * Function/operator overloading * Default parameters * Pass-by-reference
37
What command is used to compile a C++ file?
g++ -std=c++11 -c MyClass.cpp -o MyClass.o
38
What is the convention for header files in C++?
.hpp
39
What year was C++98 released?
1998
40
What major feature was introduced in C++11?
* Auto * Lambdas * Smart pointers
41
What does the command cout output to?
stdout
42
True or False: cerr flushes the buffer.
False
43
What does the function setfill do in C++?
Sets the fill character for output formatting.
44
What is function overloading?
Defining multiple versions of the same function with different parameters.
45
What is the default access level for class members in C++?
Private
46
What are constructors in C++?
Called when an object is created.
47
What are destructors in C++?
Called when an object goes out of scope.
48
What is the purpose of a destructor?
Automatically handles cleanup logic.
49
What is the main use of classes in C++?
Organize code and enable OOP.
50
Fill in the blank: C++ is a __________ of C.
Superset