Professional Documents
Culture Documents
I. Lab4 Description: Write 5 procedures: show_int (), show_float (), show_long(), show_pointer ( ), and
show_bytes () by using the C code from your Textbook Page 45 (Figure 2.4)- See below:
Requirement 1: Your Lab 4 will print the byte representations of C objects of types: int, long, float, and void *,
respectively. Observe that they simply pass show_bytes a pointer &x to their argument x, casting the pointer to
be of type “unsigned char *.” This cast indicates to the compiler that the program should consider the pointer to
be to a sequence of bytes rather than to an object of the original data type. This pointer will then be to the lowest
byte address occupied by the object (little endian machine like our Linux).
Requirement 2: You need to modify show_int (), show_float (), show_long(), show_pointer ( ), and show_bytes
() procedures’ code (see above Figure 2.4) in order to print the variable byte representation and their memory
addresses like below format (attention: your byte representation is different from my machine) :
show_int() function displays the variable byte representation and their memory addresses:
int x memory address is 0x7ffcc829369c
0x7ffcc829369c 0xee
0x7ffcc829369d 0x0a
0x7ffcc829369e 0x00
0x7ffcc829369f 0x00
show_float() function displays the variable byte representation and their memory addresses:
float x memory address is 0x7ffcc829369c
0x7ffcc829369c 0x00
0x7ffcc829369d 0xe0
0x7ffcc829369e 0x2e
0x7ffcc829369f 0x45
show_long() function displays the variable byte representation and their memory addresses:
long x memory address is 0x7ffcc8293698
0x7ffcc8293698 0xee
0x7ffcc8293699 0x0a
0x7ffcc829369a 0x00
0x7ffcc829369b 0x00
0x7ffcc829369c 0x00
0x7ffcc829369d 0x00
0x7ffcc829369e 0x00
0x7ffcc829369f 0x00
show_pointer() function displays the byte representation and their memory addresses:
0x7ffcc8293698 0xc0
0x7ffcc8293699 0x36
0x7ffcc829369a 0x29
0x7ffcc829369b 0xc8
0x7ffcc829369c 0xfc
0x7ffcc829369d 0x7f
0x7ffcc829369e 0x00
0x7ffcc829369f 0x00
//CS230 Lab4
//Programmer Name: xxxxx
//Date Completion: xxxx
//Add your Lab4 code by modifying above Figure 2.4 C code at the below:
Step 7: $ ./Lab4.exe Hint: to run the result and you must produce the
similar outputs like below:
Step 8: if your Lab4 works, it should produce the below outputs (attention: your byte representation is different
from my machine):
ival variable's memory address is 0x7fffd99424c0
ival variable's int value is 2798
ival variable's HEX value is aee
show_int() function displays variable byte representation and their memory addresses:
int x memory address is 0x7fffd994249c
0x7fffd994249c 0xee
0x7fffd994249d 0x0a
0x7fffd994249e 0x00
0x7fffd994249f 0x00
show_float() function displays variable byte representation and their memory addresses:
float x memory address is 0x7fffd994249c
0x7fffd994249c 0x00
0x7fffd994249d 0xe0
0x7fffd994249e 0x2e
0x7fffd994249f 0x45
show_long() function displays variable byte representation and their memory addresses:
long x memory address is 0x7fffd9942498
0x7fffd9942498 0xee
0x7fffd9942499 0x0a
0x7fffd994249a 0x00
0x7fffd994249b 0x00
0x7fffd994249c 0x00
0x7fffd994249d 0x00
0x7fffd994249e 0x00
0x7fffd994249f 0x00
Step 9: Attention: you will receive zero credit if your Lab4_First_LastName.c would not compile in our Linux
system.
2. Access to CS230Blackboard, click “Lab Submission” link, double click “Lab4” icon, click “Browse My
Computer” button, select Lab4_First_LastName.c file from your Desktop, and click “Submit” button. It means
that you will upload Lab4_First_LastName.c file into the BSU Blackboard. Attention, when you click “Submit”
button, you need to make sure that you have uploaded Lab4_First_LastName.c file.
Thanks!
Dr. Zhang