07 - 08 Flashcards

1
Q

Which types of variables are automatically zeroed in C?

A

Static function variables.

Static and non-static variables.

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

Where are automatic function variables stored?

A

The stack.

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

What type does malloc return?

A

A void pointer. It can store any sort of data.

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

What happens if you try to write to memory that has already been freed?

A

Undefined behaviour

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

What happens when malloc fails to allocate sufficient memory?

A

It returns NULL.

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

Is malloced data automatically zeroed?

A

No.

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

What library contains malloc and free?

A

stdlib.h

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

For a struct containing values which are pointers, why is it recommended to make a ‘deep copy’ method?

A

The struct values will contain pointers to the same data, and not its own copy of the data.

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

What is the function prototype for calloc?

A

void* calloc(size_t num, size_t size);

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

What does calloc do?

A

It takes a size and a number, and mallocs (size * number) bytes. It then zeroes all of the data.

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

What is the type ‘size_t’?

A

An unsigned integer type big enough to fit a pointer in.

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

What library holds definition for ‘size_t’ and ‘ptrdiff_t’?

A

stddef.h

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