Question

In: Computer Science

Illustrate the stack and the heap allocation. Specify what each variable value holds and where different...

Illustrate the stack and the heap allocation. Specify what each variable value holds and where different references are pointing to.

char[] class = {'C','O','M','P','1','2','2'"};
#define int n = 4;
long long fibb(long long a, long long b, int n)

{
return (--n>0)?(fibb(b, a+b, n)):(a);
}


int main()
{
fib(3);
//illustrate what memory looks like at this point
return 0;
}

Solutions

Expert Solution

Since there are no dynamic allocations statements in the given code, all the variables are allocated in Stack only.

(1)The class array is a Global array so it will be allocated in the Global variable section in Stack

(2)In the main function there is no variable declaration so the main function allocation is nil

(3)From main we call fibb() function, in that we have a,b,n are allocated, Due to the recursive call multiple allocations of 'fibb' will be there during the execution as shown below

(4)After execution completed the allocations is shown below:

Note:#define only allocates symbolic constants which will be replaced during compilation.So no memory is allocated to #define variables

The given code is having some error so i rectified them

#define n1 10

char class[] = {'C','O','M','P','1','2','2'};
long long fibb(long long a, long long b, int n)

{
return (--n>0)?(fibb(b, a+b, n)):(a);
}


int main()
{
fibb(3,2,3);
//illustrate what memory looks like at this point
return 0;
}

Related Solutions

C programming Illustrate the stack and the heap allocation. Specify what each variable value holds and...
C programming Illustrate the stack and the heap allocation. Specify what each variable value holds and where different references are pointing to. int main() { char str[20]; scanf("%[^\n]%*c", str); //illustrate how memory is allocated at this point printf("%s", str); return 0; }
C Programming Illustrate the stack and the heap allocation. Specify what each variable value holds and...
C Programming Illustrate the stack and the heap allocation. Specify what each variable value holds and where different references are pointing to. char[] class = {'C','O','M','P','1','2','2'"}; #define int n = 4; long long fibb(long long a, long long b, int n) { return (--n>0)?(fibb(b, a+b, n)):(a); } int main() { fib(3); //illustrate what memory looks like at this point return 0; }
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your...
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your program does not need to do anything else.  Indicate via comments where memory for at least one variable in each memory area is allocated. a) Write code that allocates static memory (only include one declaration): b) Write code that allocates stack memory (only include one declaration): c) Write code that allocates heap memory (only include one declaration): 2) Edit the C++ program below to include...
What is the difference between stack-dynamic and explicit heap-dynamic?  
What is the difference between stack-dynamic and explicit heap-dynamic?  
1) In each scenario below, specify each variable as a response variable, an explanatory variable, or...
1) In each scenario below, specify each variable as a response variable, an explanatory variable, or neither. a. A researcher collects measurements of VO2 max and resting heart rate on a group of subjects to study the relationship between these two variables. b. A real estate agent wants to be able to predict selling prices of houses in Vancouver. He collects data on 100 recently sold houses, recording their selling prices, size, age, number of bedrooms, and whether they had...
In each scenario below, specify each variable as a response variable, an explanatory variable, or neither....
In each scenario below, specify each variable as a response variable, an explanatory variable, or neither. Explain your choices. a. A climatologist wishes to predict future monthly rainfall in Los Angeles. To inform his predictive model, for each month of the past 30 years, he records the name of the month (Jan.-Dec.), total rainfall (mm), and the Oceanic Niño Index (a measure of sea surface temperature differences, in ºC). b. A researcher conducts an experiment in a residence for senior...
What are the different stages of memory in a heap?
What are the different stages of memory in a heap?
Pretend that our galaxy is a heap of sand, where each grain of sand is a...
Pretend that our galaxy is a heap of sand, where each grain of sand is a star, that is about 10 inches across. Since the actual Milky Way is 100,000 light years across, you can act like each inch of your pile represents 10,000 light years. Describe your heap of sand mention how thick it is, how many grains of sand there will be, what it will look like, and what properties it would have.
Pretend that our galaxy is a heap of sand, where each grain of sand is a...
Pretend that our galaxy is a heap of sand, where each grain of sand is a star, that is about 10 inches across. Since the actual Milky Way is 100,000 light years across, you can act like each inch of your pile represents 10,000 light years. Describe your heap of sand. Be specific, in terms of how thick it is, how many grains of sand there are, what it looks like, what properties it has, etc.
Question 13. For each pair of variables, specify which variable is the explanatory variable and which...
Question 13. For each pair of variables, specify which variable is the explanatory variable and which is the response variable. Also identify whether the variable is categorical or numerical. The time student spends for the study and her/his final score The car engine size and car’s maximum speed
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT