Question: Code: #include #include #include int main() { int num; int *ptr; int **handle; num = 14; ptr = (int *)malloc(2 * sizeof(int)); *ptr = num;
Code:
#include
#include
#include
int main() {
int num;
int *ptr;
int **handle;
num = 14;
ptr = (int *)malloc(2 * sizeof(int));
*ptr = num;
handle = (int **)malloc(1 * sizeof(int *));
*handle = ptr;
// Insert extra code here
return 0;
}
(Exercise) How memory is used From lecture, we've learned that there are 3 pools of memory for storing variables, based on the nature of their usage. TPS (Think-Pair-Share) activity 1 Paired with the classmate sitting next to you and do the following tasks (20 minutes): 1. Name the 3 pools for memory and what kind of variables will be stored in each pool 2. Open mem.c with your favorite text editor and discuss the following questions with your partner: a. How many variables are declared? b. How many of them are pointers? What type of data does each pointer point to? c. Which pool of memory are these variables stored in? d. Which pool of memory will the pointer ptr point to in line 12? 3. Using a piece of paper (or a drawing app), draw the 3 pools of memory and indicate the locations (in which pool?) of the variables in mem.c using boxes (like what we did in lecture). Label the boxes with variable names, their content, and their addresses. You will need to insert extra code to obtain the addresses of these variables. 4. In the same drawing, use arrows to connect each pointer to its destination. 5. Show your drawing to you TA to verify if it is correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
