What is the purpose of an ADT?
To hide implementation from the user.
What is the C standard library function used to open a file in read mode?
fopen() with mode = r
What is the syntax for declaring a pointer to an integer in C?
int * ptr
This keyword starts all macros.
What is #define?
What is the maximum value that can be stored in an unsigned char variable in C?
255
The ________ for an ADT serves as the interface for the client.
Header file
What are the 3 main modes of opening a file?
Read, Write, and Append
What are the 3 memory allocation functions used in the course?
Malloc, Calloc, Realloc
This preprocessor command removes a currently defined macro.
What is #undef?
What is the size of a float in C?
4 bytes
How should the struct for an ADT be made available in the header file?
Using a typedef
What must you always do before you're finished with a file?
Close
I couldn't think of more questions, so here's some free points!
Yay!
This allows you to concatenate variable names in a macro.
What is ##?
What is the syntax for a ternary operator in C?
(condition) ? true_expression : false_expression
This is a type that cannot be cast to a void pointer.
Float, double
What function reads a file as binary data?
Define a function pointer called function with a single int parameter and which does not return anything.
void (*function)(int a);
This macro gets the current file name.
What is __FILE__?
Given the following defines:
What is the result of the following code?
#define ADD4(x) 4+x
#define SQU(y) y*y
int main( void ){
int a = 3;
printf("%d\n", SQU(ADD4(a)));
return 0;
}
19
Write a basic constructor for an ADT called "CoolADT"
The struct is called "struct coolADT_s" and the header file is the following:
typedef struct coolADT_s * CoolADT;
CoolADT cool_create();
CoolADT cool_create(){
CoolADT newCool = (CoolADT) malloc(sizeof(struct coolADT_s));
return newCool;
}
Complete the following line to open a file called "example.txt" to read and write to it as binary data:
FILE * file =
fopen("example.txt", "br+);
What would the following return:
int ** a;
int * b;
b = 5;
a = &b;
*a += 1;
printf("a: %d, b: %d \n", *a, b);
a: 9, b: 9
Write a macro that evaluates to true if the given letter is lowercase.
#define LOWERCASE(x) (x >= 'a' && x <= 'z')
What would the dependency tree of the following makefile look like?
CC=gcc
CC_FLAGS=-Wall -Wextra -pedantic -std=c99
main: main.o list.o person.o
$(CC) $(CC_FLAGS) -o main main.o list.o person.o
main.o: main.c list.h person.h
$(CC) $(CC_FLAGS) -c main.c
list.o: list.c list.h
$(CC) $(CC_FLAGS) -c list.c
person.o: person.c person.h
$(CC) $(CC_FLAGS) -c person.c