Question

PROBLEM 5 (10 points) Consider the following code in syntax and assume stack memory allocation for nested scope is used. In t

Please show all your work

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

ANSWER

1.

At location 1, memory has been allocated to a, b, and c

b has been made to point to &c, a is not pointing to anyone

Hence the box-and-circle diagram is:

Garbage O value

2.

Since b is made to point to &c, (b, &c) are aliases.

Since no other pointer points anywhere, these are the only aliases at Location 1

3.

At location 2, memory has been allocated to *a

x has been made to point to *a, **a is pointing to &a

Hence the box-and-circle diagram at this point:

1) a o Mone

4.

The aliases are as follows:

  • x, *a
  • **a, &a
Add a comment
Know the answer?
Add Answer to:
Please show all your work PROBLEM 5 (10 points) Consider the following code in syntax and...
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
  • 5. (10%) Consider the following C code segment: int fun (int a, int b) { static...

    5. (10%) Consider the following C code segment: int fun (int a, int b) { static int count; int x, *p; x= a +b; p-malloc (sizeof (int)); a) What is the lifetime of the variable count? b) What is the scope of the variable count? c) Which part of memory is the storage allocated for x? d) What is the lifetime of the variable x? e) Which part of memory is the storage allocated for the integer pointed to by...

  • In the following code, what is the first line that introduces a memory leak into the...

    In the following code, what is the first line that introduces a memory leak into the program? (Type the line number into the box below) 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <string.h> 4: int main() { 5:            char *word1 = NULL; 6:            word1 = malloc(sizeof(char) * 11); 7:            word1 = "bramble"; 8:            char *word2 = NULL: 9:            word2 = malloc(sizeof(char) * 11); 10:          word2 = word1; 11:          return 0; 12: }

  • 1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int...

    1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int start, int end, int *results) { int length = end - start; results = malloc(sizeof(int) * length); for (int i=start; i<end; i++) { *results = i; results++; } } void printArray(int *arr, int length) { for (int i=0; i<length; i++) { printf("%d ", arr[i]); } } int main() { int *x; int s = 2; int e = 11; range(s, e, x); printArray(x, e...

  • 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....

  • Q6 Common Mistakes in C 5 Points Each of the following code samples below is making...

    Q6 Common Mistakes in C 5 Points Each of the following code samples below is making a common mistake in C. From the options: probable segfault, double free, incorrect use of free, logic error, memory leak, and no error select the error type that best categorizes the mistake. You can assume all the code has the necessary #include macros. Also you should assume that the system is 32-bit. 1) #DEFINE PASSWORD "correct horse battery staple" char *check_permissions (char *user_guess) {...

  • Given the following source programs, write down the letter that correspond to the right answer #include...

    Given the following source programs, write down the letter that correspond to the right answer #include <stdio.h> #ifndef MEMORY #include "myhead.h" #include <stdlib.h> myhead.h #include <string.h> int main() { #endif char *text= MEM(SIZE, char); #define SIZE 10 COPY_TEXT (text, MSG); #define MSG "CS262" newtext (text); #define MEM(size, type) SHOW (text); (type *) malloc(size * sizeof(type)) free (text); #define COPY_TEXT (dest, source) return 0; strcpy (dest, source) } text.c #define SHOW (x) printf("Output: %s\n", x) void newtext (char *text) { int...

  • Please write the complete code in C. Write a C function that prints the minimum spanning...

    Please write the complete code in C. Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the...

  • 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 program Here we see a Stack ADT implemented using array. We would like the stack...

    c program Here we see a Stack ADT implemented using array. We would like the stack to be usable for different max sizes though, so we need to use dynamic memory allocation for our array as well. #include <stdio.h> #include <stdlib.h> typedef struct { int *data;   // stack data, we assume integer for simplicity int top;     // top of the stack int maxSize; // max size of the stack } Stack; void StackInit(Stack* stack, int size) {     // this...

  • D and e only. Can someone help with this. C++ only. Show work if possible. Thanks...

    D and e only. Can someone help with this. C++ only. Show work if possible. Thanks Name: 3, (30%) Consider the following class definition: class SomeClass public: SomeClass (): SomeClass (); void set1 (int val); void set2 (int val); void add (SomeClass m); int getl ) int get2 0 private: static int numobjs; int meml; int mem2 SomeClass x1, x2; (a) Draw a box around every mutator function in this class. (b) Circle every accessor function in this class. (c)...

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