I/O
Bitwise
ADTs
C programming
Grab bag
100

Which file open mode will not create a new file is the given one does not exist?

r (read)

100

What is the operation for inverting all bits?

~, complement

100

What is the purpose of an ADT?

To hide implementation from the user.

100

This qualifier asks the compiler to store the variable in a CPU register.

Register

100

C is ____ type-checked, which occurs at compile time.

Statically

200

What does the function fgetc() do?

Gets one character from a file.

200

1011 ^ 1100 =

0111

200

The ________ for an ADT serves as the interface for the client.

Header file

200

This qualifier tells the compiler to not optimize code.

Volatile

200

C is ____ typed, which means you can get around type restrictions.

Weakly

300

Which function writes to a file in binary?

fwrite

300

1001 << 2 =

0100

300

How should the struct for an ADT be made available in the header file?

Using a typedef

300

Define a function pointer called function with a single int parameter and which does not return anything.

void (*function)(int a);

300

What integer value does Thursday have in enum days?

enum days{ Sunday = 4, Monday, Tuesday = 0, Wednesday, Thursday, Friday = 11, Saturday };

2

400

Which function sets the position in the given file to the given offset?

fseek

400

char a = 0xf2;

a >> 4 =

0xff

400

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;

}

400

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;

};

400

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


500

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");

500

unsigned char a = 0b10001000;

char b = 0b11110000;

~a & b || 0b00110011=

1

500

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

500

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

500

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

M
e
n
u