Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions