Question

In: Computer Science

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;
}

Solutions

Expert Solution

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;
}


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


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; }
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; }
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...
C# Programming using Windows Form 1. Define a variable named isTrue that stores a value of...
C# Programming using Windows Form 1. Define a variable named isTrue that stores a value of whether something is true or false. Set this variable    to the negative. Output this variable to the txtIsTrue textbox. 2. Define a variable named favoriteGame that could store the name of a game. Set this variable's value to your favorite game. Output this variable to the txtFavoriteGame textbox. 3.. Define a variable named pi that can store real numbers. initialize it to a value...
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
Do a trace on the binarySearch method below: variable key holds the value 17, and variable...
Do a trace on the binarySearch method below: variable key holds the value 17, and variable list is a reference to an array with these values {9, 20, 23, 28, 33, 38, 42, 48, 54, 61,73}. public static int binarySearch(int[] list, int key) { Each row in the table below corresponds to one iteration of the while loop in the method above. You can add or remove rows according to the actual number of iterations. The first row’s information corresponds...
In C Programing Create a stack using an array. Define the index variable of the array...
In C Programing Create a stack using an array. Define the index variable of the array name to be stacktop. Initially set stacktop to -1. Next create two functions push and pop. Both take as input 3 items: a pointer to the stack in memory, stacktop, and maxstack. Make sure to inc stacktop by one and also remember that stacktop[0] is the bottom of the stack and by stack rule cannot be accessed until all the other items are popped....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT