C Dynamic Memory Flashcards

(7 cards)

1
Q

What is the Heap Used for?

A

Dynamic allocation

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

What does malloc() and free() do?

A

Malloc assigns memory and free frees it once we are done

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

What is size_t?

A

Just unsigned int

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

What happens if request more memory than we have

A

Returns null

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

If I wanted to createa typedef string, how would I initilize it in main?

A

In main, you would want to use strcpy(location, name);

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

What is a memory leak?

A

Must free() memory or we will have memory on the heap we can no longer get to

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

When making a typedef struct, when should you use sizeof and strlen/strcpy?

A

Use sizeof to malloc the pointer object while use strlen/strcpy if you don’t have a pointer object

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