.111 WK 5-10 Flashcards

Nigel + Adrian

1
Q

What is a pointer

A

variable that contains the address of another - signified by *

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

what is the size of a pointer?

A

always the size of that system’s memory address size

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

What are pointers useful for?

A

passing variables to functions by ref

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

How do you get the memory address of var?

A

&var

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

A string is…

A

an array of characters terminating with \0

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

what do you use to indicate a a) string, b) decimal?

A

a) %s b) %d

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

How do you compare 2 strings?

A

using strcmp() - returns -1/0/1 (less than/equal to/greater than) based on ASCII codes

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

How do we dynamically allocate space in memory?

A

using malloc(int) to allocate and free(var) to deallocate

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

What’s an API?

A

software interface between your program + something else - set of operations defined for interacting w/ a system in a controlled way

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

How do you use an API

A

include <headerfile.h></headerfile.h>

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

What is a file?

A

ideally persistent storage of a collection of data, either text or binary + can be accessed serially or by random access

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

EOF means??

A

end of file

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

How to read/write to a text file?

A

getchar() to return next input char + putchar(int) to put char on standard output

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

How to open a file?

A

FILE fopen(char name, char mode)

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

file modes?

A

r, a, w

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

How do you find where you are in the file?

A

long ftell(FILE *stream) - find out how many bytes from the start we are

17
Q

Pros of single file projects?

A
  • only 1 file to parse for compiler
  • programmer only needs to scroll through one place
  • copying/distributing project is just 1 source file + no dependencies - easyyy
18
Q

Cons of single-file projects?

A
  • not scalable
  • scrolling becomes unmanageable
  • difficult for teams to co-edit 1 file
  • harder to package up functions for reuse - danger of hidden side effects
19
Q

What is the difference between “” and <> in #include statements?

A

”” for in same file and <> for in system files

20
Q

What is forward declaration?

A

defining the function type name and types of variables to help compiler and IDE when parsing functions from header files

21
Q

How should libraries be named?

22
Q

What does gcc -c do?

A

create objects/part compiled files (saves from file.c to file.o)

23
Q

How do you turn an object into a library?

A

ar rcs libx.a file.o
gcc -o prog prog.c -lx

24
Q

Why do we need dynamic data structures?

A

costly (time + money) to shift data around in static structures - inefficient
need to know size to declare
may run out of space or take up unnecessary space

25
How to add to dynamic data structure?
allocate space for a node from the heap (use malloc()) find where to add the item to the structure adjust pointers accordingly
26
What is version control?
principled approach to tracking your code base
27
What do versions record and how often is it recorded?
records differences (additions, substitutions + removals) between versions with no.s + timestamps too only records when you choose to commit