Day 11 Recap Questions
- What is the difference between stack and heap memory?
- What is dynamic memory allocation in C?
- What is the memory leak problem?
- What is the difference between malloc, realloc, and calloc?
- What do we use valgrind to check for?
- Consider the
exclaim
function below. Do you see any problems with this function?
// Return a C character string containing n exclamation points.
// n must be less than 20.
char* exclaim(int n) {
char s[20];
assert(n < 20);
for (int i = 0; i < n; i++) {
s[i] = '!';
}
s[n] = '\0';
return s;
}