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!!!
*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;...
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...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Create a C++ project to compute the following: 1. Numerical differentiation of x at a point...
Create a C++ project to compute the following: 1. Numerical differentiation of x at a point 2. Numerical integration of 2 points of x 3. Finding a root between 2 points of x. Let the function is given as 4x5+ 2x3+x-9 In your project, the user will choose what he or she wants to do. Maybe the user wants to do differentiation (choice 1)or integration (choice 2) or finding root (choice 3). In case of choice 1, the user will...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT