Dynamic memory
Program translation
ADTs
Preprocessor*
Miscellaneous
100

When should you use dynamic memory vs stack memory?

Use dynamic memory when you need the data to persist or when it may need to resize.

100

What are the names of the 2 tables we talked about in class that are used during linking?

Symbol table and relocation table.

100

What is abstraction and why is it useful?

Abstraction is when you hide the underlying details of something, providing a simpler interface. It allows you to change the implementation without changing the interface.

100

What is the preprocessor and what things can it do?

It runs before the compiler, taking C code and spitting out different C code. Can do things like text replacement and conditional compilation

100

What do bitwise operators do as opposed to logical operators?

They do logic operations on each bit of numbers instead of the numbers as a whole.

200

What type does malloc return?

void*

200

What are ELF files?

A standard executable file format that stores necessary information for linking and executing.

200

How do we make methods in C despite not being able to put them inside structs?

We make a function that takes a pointer to the “this” instance. BONUS: why does it take a pointer instead of the instance itself?

200

Why can’t you reassign a constant defined by #define? Because it doesn’t exist at runtime.

Before even compiling, every reference to the constant was replaced by hardcoding its literal value. It would be like running 10++.

200

What does fopen() do and what type does it return?

Opens a file and returns a FILE*

300

What is memory leak?

When the address of allocated memory is lost, so the memory is unable to be freed.

300

What is the step called when you run an executable?

Loading

300

How do we hide the underlying details of an ADT from the user files in C?

Only expose the interface through a header file. Don’t define the struct’s internals in the header, just typedef a pointer to an anonymous struct. BONUS: how do we solve the problem of the header file and the implementation file typedef’ing the same thing twice?

300

What is the name of the common conditional compilation technique used in header files? BONUS: what can happen if we don’t use them?

Include guards. If we don’t use include guards, a file can get included multiple times. We can even have infinite recursion.

300

What can bitwise operators be used for?

Accessing a manipulating the bits of variables, cramming multiple values into the same variable, and some optimizations (ex. exponents)

400

What is a dangling pointer?

A pointer that points to deallocated memory.

400

What is the symbol table?

A table that maps function names to their addresses.

400

How can we make an ADT “generic” in C?

Make it store void*’s or unions so that multiple different types can be stored in it.

400

What are the benefits of makefiles?

We don’t have to run multiple commands every time we want to compile a program. It will search the dependency graph to see what has changed and what needs to be recompiled, saving time.

400

What is the best function to use to read a file line by line and why? 

getline(). It will automatically resize your buffer for you, so it will always give you the full line each time.

500

What happens to leaked memory when the program exits?

It is deallocated; all of the process’s memory is deallocated.

500

What is the relocation table?

A table that stores where the blank addresses are so we can fill them in later during linking.

500

What is the downside of using void* for generics rather than unions?

You cannot cast a floating point type to a void*

500

Why is this macro wrong? Name an example when it will fail. #define SQUARE(x) (x)*(x)

double oneNinth = 1 / SQUARE(3)

500

What do you “and” a value with to turn off the 3rd bit? BONUS: what do you call the thing you “and”’d it with?

A number that is all 1s and a 0 in the 3rd bit. It’s called a bit mask.