Which file open mode will not create a new file is the given one does not exist?
r (read)
What is the operation for inverting all bits?
~, complement
What is the purpose of an ADT?
To hide implementation from the user.
This qualifier asks the compiler to store the variable in a CPU register.
Register
C is ____ type-checked, which occurs at compile time.
Statically
What does the function fgetc() do?
Gets one character from a file.
1011 ^ 1100 =
0111
The ________ for an ADT serves as the interface for the client.
Header file
This qualifier tells the compiler to not optimize code.
Volatile
C is ____ typed, which means you can get around type restrictions.
Weakly
Which function writes to a file in binary?
fwrite
1001 << 2 =
0100
How should the struct for an ADT be made available in the header file?
Using a typedef
Define a function pointer called function with a single int parameter and which does not return anything.
void (*function)(int a);
What integer value does Thursday have in enum days?
enum days{ Sunday = 4, Monday, Tuesday = 0, Wednesday, Thursday, Friday = 11, Saturday };
2
Which function sets the position in the given file to the given offset?
fseek
char a = 0xf2;
a >> 4 =
0xff
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;
}
Create a struct with bitfields for a specialized chip:
- 2 bits specify input
- 1 bit specifies a flag
- 5 bits are used for data
struct bitField{
unsigned char input : 2;
unsigned char flag : 1;
unsigned char data : 5;
};
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
Finish the line below so that it opens the .c file of the current program to read it in binary.
FILE * file =
FILE * file = fopen(__FILE__, "rb");
unsigned char a = 0b10001000;
char b = 0b11110000;
~a & b || 0b00110011=
1
I couldn't think of any more ADT questions, so here's a random one:
What is the output of this code?
int x(){ return 10;}
int y(){ return 20;}
int main(){
int a = ( x(), y() );
printf("a=%d", a);
return 0;
}
20
What is the size of the union below?
union u{
char c[8];
int i[4];
void * v[3];
double d;
unsigned short s[10];
};
24 bytes
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