Question

In: Computer Science

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 %c, char2 %c\n", *(*p2 + 2) + 1, *(*p2 + 2 + 1));

return 0; }

Solutions

Expert Solution

Here is the full memory diagram of above program --->

number written below any box tells address of that memory block in main memory and value in the box tells value stored at that memory address in main memory.

Char *p1 = str; // p1 = 2000

p1

2000

5000

p1++;

p1 *p1 = ‘s’

2001

5000

Char *p2 = &p1;

p2

5000

7000

p3 = &str[4];

p3 *p3 = ‘1’

2004

8000

clearly p3-p1 ===2004-2001 = 3

*p2 = 2000

*p2+2 = 2002

*(p2+2) +1= ‘1’+1 = ‘2’

*(*p2+2+1) = value at address 2003 which is 1

output of program

1. str = s111 NYU
3. char1 2, char2 1


Related Solutions

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; }
Draw a diagram that highlights the main pathophysiology of coronavirus.
Draw a diagram that highlights the main pathophysiology of coronavirus.
Draw diagram showing 8088 microprocessor connected to 4 memory chips each of 32K, mapped to memory...
Draw diagram showing 8088 microprocessor connected to 4 memory chips each of 32K, mapped to memory address starting from D0000.
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...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main –...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main – Should accept input of five numeric grades from the user USING A LOOP.   It should then calculate the average numeric grade.    The numeric average should be passed to the determine_grade function. determine_grade – should display the letter grade to the user based on the numeric average:        Greater than 90: A 80-89:                 B 70-79:                 C 60-69:              D Below 60:           F Modularity:...
Draw a cash flow diagram for a cash flow that starts at $1,000 at the end...
Draw a cash flow diagram for a cash flow that starts at $1,000 at the end of the first month and increases by $100 each month after that in perpetuity with an interest rate of 21% annual compounded monthly (Draw at least the first 5 months). What is the present value of this cash flow?
Define Electrodialysis (ED), draw a schematic diagram of the process, and determine the main characteristics of...
Define Electrodialysis (ED), draw a schematic diagram of the process, and determine the main characteristics of ion exchange membranes to be used. What are the process limitations in ED systems? then differentiate between dialysis and osmosis phenomena.
a)Draw the diagram and describe the key components of a PLD. b)Describe the main advantage in...
a)Draw the diagram and describe the key components of a PLD. b)Describe the main advantage in using PLD deposition versus other Physical Vapour Deposition methods.
Course: Computer Architecture Theme: Internal Memory Draw the diagram of a typical 16 Mb DRAM (4M...
Course: Computer Architecture Theme: Internal Memory Draw the diagram of a typical 16 Mb DRAM (4M X 4) and explain its action. Draw the diagram of an SRAM cell and explain its action.
Write a program using c, c++, or java that have four dynamic memory partitions of size...
Write a program using c, c++, or java that have four dynamic memory partitions of size 100 KB, 500 KB, 200 KB, and 450 KB. The program should accept from user the number of processes and their sizes. Then output the assignment of processes using the next fit algorithm (specifying which process, if any, is block).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT