.111 WK 5-10 Flashcards
Nigel + Adrian
What is a pointer
variable that contains the address of another - signified by *
what is the size of a pointer?
always the size of that system’s memory address size
What are pointers useful for?
passing variables to functions by ref
How do you get the memory address of var?
&var
A string is…
an array of characters terminating with \0
what do you use to indicate a a) string, b) decimal?
a) %s b) %d
How do you compare 2 strings?
using strcmp() - returns -1/0/1 (less than/equal to/greater than) based on ASCII codes
How do we dynamically allocate space in memory?
using malloc(int) to allocate and free(var) to deallocate
What’s an API?
software interface between your program + something else - set of operations defined for interacting w/ a system in a controlled way
How do you use an API
include <headerfile.h></headerfile.h>
What is a file?
ideally persistent storage of a collection of data, either text or binary + can be accessed serially or by random access
EOF means??
end of file
How to read/write to a text file?
getchar() to return next input char + putchar(int) to put char on standard output
How to open a file?
FILE fopen(char name, char mode)
file modes?
r, a, w
How do you find where you are in the file?
long ftell(FILE *stream) - find out how many bytes from the start we are
Pros of single file projects?
- 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
Cons of single-file projects?
- 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
What is the difference between “” and <> in #include statements?
”” for in same file and <> for in system files
What is forward declaration?
defining the function type name and types of variables to help compiler and IDE when parsing functions from header files
How should libraries be named?
libyap.a
What does gcc -c do?
create objects/part compiled files (saves from file.c to file.o)
How do you turn an object into a library?
ar rcs libx.a file.o
gcc -o prog prog.c -lx
Why do we need dynamic data structures?
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