Question
What kind of memory allocation occurs on the blue line of code below? int my_fun() { char *s = (char *) malloc(10); } a. stack
What kind of memory allocation occurs on the blue line of code below?
int my_fun() {
char *s = (char *) malloc(10);
}
a. stack allocation
b. heap allocation
c. both stack and heap allocation
d. neither stack nor heap allocation
Which is the correct way to allocate memory to make a copy of a string foo? (This code shows only the memory allocation, not the copying.)
a. char *s_copy = (char *) malloc(foo);
b. char *s_copy = (char *) malloc(strlen(foo));
c. char *s_copy = (char *) malloc(strlen(foo) + 1);
The line of code below can be fixed by changing one thing? What is it?
int *xp = (int *)malloc(1);
a. The argument passed to malloc()
b. The (int *) in front of malloc
c. The int * at the beginning of the line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started