Question

In: Computer Science

Create a memory diagram for the following C program when the program reaches point 1. void...

Create a memory diagram for the following C program when the program reaches point 1.

void foo (int *a);

int bar(int *x);

int search(int *c);

int main(void)

{

int q, p=10;

q= search(&p);

return 0;

}

void foo(int *a)

{

*a += 2;

//point 1

*f *= 10;

}

int bar(int *x)

{

return 2* *x;

}

int search(int *c)

{

int z= *c + bar(c);

foo(c);

return z;

}

Solutions

Expert Solution

For given c program:

void foo (int *a);

int bar(int *x);

int search(int *c);

int main(void)

{

int q, p=10;

q= search(&p);

return 0;

}

void foo(int *a)

{

*a += 2;

//point 1

*f *= 10;

}

int bar(int *x)

{

return 2* *x;

}

int search(int *c)

{

int z= *c + bar(c);

foo(c);

return z;

}

Summary: Starting execution from main function, two variables p type integer equals 10 and address of p passed as parameter calling search function, from search bar with address of p passed bar computes 2 * 10 and returns 20 and bar discarded from stack, z value computed as 30 in search, after foo is called where *a becomes 12.


Related Solutions

Draw the main memory diagram as captured at the end of the C program
FOR C PROGRAMMING LANGUAGE Draw the main memory diagram as captured at the end of the C program (i.e. return 0; statement). Your diagram must clearly shows where str, p1, p2, and p3 are pointing to, when the program terminates. int main(void) { char str[] = "cs111 NYU"; char* p1 = str; p1 ++; char** p2 = &p1; char* p3 = &str[4]; printf("1. str = %s\n", p1); if(p3 - p1 == 4) { printf("2. p1 == p3\n"); } printf("3. char1...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory so you store that number of integers. Write integers in order starting from 1 until you fill all that memory. Print the addresses and values of the first and the last integer stored in the memory.
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory so you store that number of integers. Write integers in order starting from 1 until you fill all that memory. Print the addresses and values of the first and the last integer stored in the memory. Help ASAP!!!
Write a C program to create a series of processes, as shown below in the diagram....
Write a C program to create a series of processes, as shown below in the diagram. P |------ ---- > c1 |------------>c2                              |------- ------>c3 ---------->c4                             In other words, the parent process p creates process c1, c1 creates c2 and c3, and c3 creates c4. A sample run of the program shows Your program should output something similar to what is shown above. You could optionally use wait/waitpid/sleep/exit in your program. Comment your code to show where you created...
Write a C program to create a series of processes, as shown below in the diagram....
Write a C program to create a series of processes, as shown below in the diagram. P - ------------------ > c1 ------------>c3    |                                          |    |------------------> c2 |----- >c4 In other words, the parent process p creates processes c1 and c2, c1 creates c3 and c4.
*Answer in C program* Given a program as shown below: #include <stdio.h> void function1(void); void function2...
*Answer in C program* Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37;...
Program in Java Create a stack class to store integers and implement following methods: 1- void...
Program in Java Create a stack class to store integers and implement following methods: 1- void push(int num): This method will push an integer to the top of the stack. 2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
Program in Java Create a queue class to store integers and implement following methods: 1- void...
Program in Java Create a queue class to store integers and implement following methods: 1- void enqueue(int num): This method will add an integer to the queue (end of the queue). 2- int dequeue(): This method will return the first item in the queue (First In First Out). 3- void display(): This method will display all items in the queue (First item will be displayed first). 4- Boolean isEmpty(): This method will check the queue and if it is empty,...
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...
Create a program named MergeSort.java then copy the following code to your program: public static void...
Create a program named MergeSort.java then copy the following code to your program: public static void mergeSort(int[] arr){    mergeSortRec(arr, 0, arr.length-1); } private static void mergeSortRec(int[] arr, int first, int last){    if(first<last){     int mid=(first+last)/2; mergeSortRec(arr, first, mid);     mergeSortRec(arr, mid+1,last);     merge(arr, first, mid, mid+1, last);    } } private static void merge(int[] arr, int leftFirst,    int leftLast, int rightFirst, int rightLast){    int[] aux=new int[arr.length];    //extra space, this is downside of this algorithm   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT