Question

Examine the function below and answer the following questions. int gLobal = 25; // declared outside...

Examine the function below and answer the following questions.

int gLobal = 25; // declared outside function

int func( int X, char *Y, BYTE Z )

{

int a;

char b[] = “The lazy dog ate the red fox before jumping over it.”

char *c;

c = (char *) malloc(512K);

a = b[0];

return a;

}

--

b. How many bytes used on the stack for ‘Z’.

c. How many 4K pages of physical memory are needed for the above malloc?

d. How many bytes are used on the stack for the local variables in this function?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

b)

Since Z is of type 'BYTE', 1 byte of memory is allocated on the stack for Z

c)

Using malloc we are allocating a memory of 512K in heap/main memory.
So number of physical memory pages = 512K/4K = 128

d)

The local variables here are

1. int a; => 4 bytes(number of bytes varies for different platforms)
2. char b[] = "The lazy dog ate the red fox before jumping over it." => 52 bytes (since each charactter is of size 1 byte)

3. char *c; => it needs 4 bytes of memory since it is a character pointer
4. int X => 4 bytes
5. char *Y => 4 byte
6. BYTE Z => 1 byte

Hence, 69 bytes are used for the local variables in this function


PLEASE UPVOTE IF THE ANSWER WAS HELPFUL

Add a comment
Know the answer?
Add Answer to:
Examine the function below and answer the following questions. int gLobal = 25; // declared outside...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Malloc function For the prelab assignment and the lab next week use malloc function to allocate...

    Malloc function For the prelab assignment and the lab next week use malloc function to allocate space (to store the string) instead of creating fixed size character array. malloc function allows user to allocate memory (instead of compiler doing it by default) and this gives more control to the user and efficient allocation of the memory space. Example int *ptr ptr=malloc(sizeof(int)*10); In the example above integer pointer ptr is allocated a space of 10 blocks this is same as creating...

  • problem 2 and 3 1. For each variable (a-g) describe whether the variable itself is global...

    problem 2 and 3 1. For each variable (a-g) describe whether the variable itself is global or local, static or not static, and initialized or uninitialized. (Hints: Global variables are always static. Local variables become static when declared with 'static'. For pointers, consider the pointer itself, not anything the pointer might point to.) 2. For each variable (a-g), describe where it is located when DoFunctionB is running. That is, for each variable, describe whether it is on the stack, in...

  • C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function...

    C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...

  • 1. Answer the questions considering the following functions headers: int func1(int x, double w) double func2(string...

    1. Answer the questions considering the following functions headers: int func1(int x, double w) double func2(string I, int y, double r) char func3(int z, int s, double t, char a) a. How many parameters does function func1 have? What is the type of function func1? b. How many parameters does function func2 have? What is the type of function func22 c. How many parameters does function func3 have? What is the type of function func3? d. Write a C++ statement...

  • Answer the following multiple choice questions: 1) What is scope? a. The region between curly braces....

    Answer the following multiple choice questions: 1) What is scope? a. The region between curly braces. b. The region of code where a name can be used to reference a piece of data. c. The name for a piece of memory that holds a value. d. The abstraction of a concept that is important to remember. 2) Which of the following is not an Object Oriented concept? a. Procedure Calling. b. Inheritance. c. Access Specifiers. d. None of the above....

  • Run the C program below and complete the table showing all the variables. Add printf function...

    Run the C program below and complete the table showing all the variables. Add printf function calls to obtain the addresses and values of all 13 variables. (Count the array (ca) as 3 variable/values and also include argc and argv in the table). The table must show the Address, Name, Datatype, Scope, and Value of each variable on the stack. (Hint: use the sizeof function to double check your addresses.) Explain how different the actual memory allocations are from what...

  • 2018 CIS360: Info Tech Hardware & Software 6. Short answer questions Answer the following questions in...

    2018 CIS360: Info Tech Hardware & Software 6. Short answer questions Answer the following questions in the space below: a) b) c) (2 points) Name any five components of the LMC computer and their real-world equivalents (2 points) State any two guidelines that define a von Neumann architecture (2 points) The LMC computer executes instructions sequentially except when which type of instruction is encountered? (2 points) What is a register? Where is it located? What's the benefit of incorporating registers...

  • ****find_last_node.c #include <stdio.h> #include "linked_list.h" int main(){    ...

    ****find_last_node.c #include <stdio.h> #include "linked_list.h" int main(){       struct node *linked_list = NULL;    linked_list = add_to_list(linked_list, 5, 'a');    linked_list = add_to_list(linked_list, 10, 'b');    linked_list = add_to_list(linked_list, 4, 'c');    linked_list = add_to_list(linked_list, 10, 'd');    linked_list = add_to_list(linked_list, 5, 'e');    linked_list = add_to_list(linked_list, 7, 'f');    linked_list = add_to_list(linked_list, 5, 'g');    linked_list = add_to_list(linked_list, 3, 'h');    int search_number;    printf("Enter number you want to search for:");    scanf("%d", &search_number);    struct node *last_node = find_last(linked_list, search_number);    if (last_node != NULL)    {        printf("Node found: value = %d and...

  • The following figure shows how to construct a module of chips that can store 1 MB...

    The following figure shows how to construct a module of chips that can store 1 MB based on a group of four 256-Kbyte chips. Let’s say this module of chips is packaged as a single 1-MB chip, where the word size is 1 byte. Give a high-level chip diagram of how to construct a 8-MB computer memory using 8 1-MB chips. How many memory addresses lines do you need (In the example, it is 20 lines -MAR)? Question 8 options:...

  • Implement a rabin_hash method to make the following code work: int rabin_karp_batchmatch(int bsz, /* size of...

    Implement a rabin_hash method to make the following code work: int rabin_karp_batchmatch(int bsz, /* size of bitmap (in bits) to be used */ int k, /* chunk length to be matched */ const char *qs, /* query docoument (X)*/ int m, /* query document length */ const char *ts, /* to-be-matched document (Y) */ int n /* to-be-matched document length*/) { /*if the to-be-matched document is less than k length, return false*/ if (n < k) return 0; /*start our...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT