C Programming 07/8 Flashcards

1
Q

What is Static Allocation?

A

Storage allocated statically when program starts, freed automatically when program ends.
• Variable defined with the static identifier in functions.
• Both static and non-static variables at the global scope.

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

What is Stack Allocation?

A

Memory automatically allocated when function is executed.
• Fixed size of memory automatically allocated at run- time.
• Used for variables that are local to a block

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

What is Dynamic Allocation?

A

Memory allocated at run-time.
• Done manually by the programmer.
• Lifetime of the memory is handled by the programmer.

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

What is malloc?

A

Allocates a new block of raw memory of certain size (in bytes)
• void *malloc(size_t size);
• Returns NULL if there is insufficient memory left in the OS.
• Memory returned has no type, and will be filled with random data

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

What is free?

A

Returns a block of memory to the OS.
• void free(void *ptr);
• There is no automatic memory management
• Undefined behaviour if you read or write from a pointer into a block of already freed memory.

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