Question: Code: #include int main() { int i; int four_ints[4]; char * four_c; for (i=0; i four_ints[i] = 2; printf(%x , four_ints[0]); four_c = ( char

 Code: #include int main() { int i; int four_ints[4]; char* four_c;

Code:

#include

int main() {

int i;

int four_ints[4];

char* four_c;

for(i=0; i

four_ints[i] = 2;

printf("%x ", four_ints[0]);

four_c = (char*)four_ints;

for(i=0; i

four_c[i] = 'A'; // ASCII value of 'A' is 65 or 0x41 in Hex.

// Add your code for the exercises here

return 0;

}

1. Open memCast.c, compile and run the program. What do you expect the 2. Before changing the code, what do you expect the program to print if you 3. Insert a print statement to print out four_ints[O] at the end of the program 4. Now add a print statement to the program so it will print out four_ints[1] 5. Let's study the code carefully and investigate what happened. No, the memory program to print? (ox in printf allows an integer to be printed in Hex format) print four_ints[O] again at the end of the program? and verify your answer from (2) What does it print? Are you surprised (or lost) by the results? did not go crazy a. How many array(s) were allocated in this program? b. Are four_ints and four_c pointing to the same location? c. Verify your answer of (b) by printing out the values of four_ints and four c 6. Write a loop to print out the addresses (int Dec) and values (in Hex) of all the elements of four_ints. What is the difference in addresses between two consecutive elements? Discuss what this difference means. 7. Use a piece of paper to draw the layout of the array horizontally so that the smallest address begins from the RIGHT-hand-side. Indicate the address and value of each element based on the results of (6). You can draw it digitally 8. Now, write a loop to print out the same information of four_c as you did in (6) What is the difference in addresses between two consecutive elements? Discuss what this difference means. 9. Use the same piece of paper (or file) from (7) to draw a similar structure of four 10. By comparing the layout of the array pointed by the two pointers, what do you observe in terms of how C accesses memory when the index of an array is incremented

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!