CIS3355: Data Structures

The University of Texas at El Paso

Professor Kirs

 

RAM Allocation: Sample Problems and Exercises

 

1.0010   How many bytes of contiguous storage are needed for each of the following data types?

 

     a.   char:                                  d.   int:                 

     b.   double                              e.   long:            

     c.   float                                   f.   long double

 

      SEE SOLUTION

 

1.0100   How do we get a particular address in RAM?

 

      SEE SOLUTION

 

1.0200   How do we find which addresses we are using in RAM?

 

      SEE SOLUTION

 

1.0300   We Already know that the ASCII Charatcer ‘F’ is stored as the integer value 70. What is the difference (in terms of RAM storage) between storing the integer 70 and the character ‘F’ ?

 

      SEE SOLUTION

 

7.0010  Suppose that we find that the following variables can be associated with the given locations in RAM (note: this is a 2’s compliment machine):

      Variable         data type             RAM location

     vara            char                             4060  

     varb            char                             4063

     varc            short                            4065

     vard            signed short               4068

     vare            unsigned short           4072

     varf             long                             4077

     varg            unsigned long            4084

 

Suppose also that I were to look into RAM and see the following:

       

 

4058

4059

4060

4061

00010010

11001011

01011001

00010010

4062

4063

4064

4065

11010001

10011100

00100001

00100100

4066

4067

4068

4069

00001111

000000001

11110101

00011101

4070

4071

4072

4073

00110011

00100100

10001001

11011001

4074

4075

4076

4077

11101101

00111011

10001001

11111110

4078

4079

4080

4081

10110111

11001001

01101001

11000100

4082

4083

4084

4085

00100100

11111100

11000001

00000000

4086

4087

4088

4089

01001001

 

00000001

00011010

10001001

 

a    What is the decimal value of vara?

 

      SEE SOLUTION

 

b.   What is the ASCII character for vara?

 

      SEE SOLUTION

 

c.   What is the decimal value of varb?

 

      SEE SOLUTION

    

d.   What is the ASCII character for varb?

 

      SEE SOLUTION

    

e.   What is the decimal value of varc?

 

     SEE SOLUTION

 

f.    What is the ASCII character for varc?

 

     SEE SOLUTION

 

g.   What is the decimal value of vard?

 

     SEE SOLUTION

 

h.   What is the ASCII character for vard?

 

     SEE SOLUTION

 

i.    What is the decimal value of vare?

 

     SEE SOLUTION

 

j.    What is the ASCII character for vare?

 

     SEE SOLUTION

 

k    What is the decimal value of varf?

 

     SEE SOLUTION

 

l.    What is the decimal value of varg?

 

     SEE SOLUTION

 

10.00  Given the Declarations:char  mystring[10];

                                                      long  mylong;    

                                                      int    myint = 467;   // assume the data type int requires 2-bytes

 

and the command:              printf(“%lu,  %lu  %lu\n”,  mystring, &mylong, &myint);

 

which yields the output:      4060   4072  4078

 

When I look into RAM on my two’s compliment machine, I find:

 

 

4058

4059

4060

4061

00101101

01101110

01000111

01101111

4062

4063

4064

4065

01101111

01100100

00100000

01001100

4066

4067

4068

4069

01110101

01100011

01101011

00000000

4070

4071

4072

4073

00110011

00100100

11111111

11111111

4074

4075

4076

4077

11111110

10111011

10001001

11111110

4078

4079

4080

4081

 

 

 

 

 

a.   What would the command:  printf(“%c”, mystring[6]);  yield?

 

     SEE SOLUTION

 

b.   What would the command:  printf(%ld”, mylong); yield?

 

     SEE SOLUTION

 

c.   Show exactly how and where would myint be stored?

 

     SEE SOLUTION

 

 

10.02    Given the Declarations:   short  myshort[5];

                                                      long  mylong;    

                                                      char  mystring[] = “Hi”;  

 

 

and the command:              printf(“%lu,  %lu  %lu\n”, &myshort[3], &mylong, mystring);

 

which yields the output:      4066   4072  4078

 

When I look into RAM on my two’s compliment machine, I find:

 

4058

4059

4060

4061

00101101

01101110

00000000

00101111

4062

4063

4064

4065

01101111

01100100

00100000

01001100

4066

4067

4068

4069

01110101

01100011

01101011

00000000

4070

4071

4072

4073

00110011

00100100

11111111

11111111

4074

4075

4076

4077

11111101

00111000

10001001

11111110

4078

4079

4080

4081

 

 

 

 

 

 

a.   What would the command:  printf(“%d”, myshort[0]);  yield?

 

     SEE SOLUTION

 

b.   What would the command:  printf(%ld”, mylong); yield?

 

     SEE SOLUTION

 

c.   Show exactly how and where mystring would be stored?

 

     SEE SOLUTION

 

15.000 Suppose that I entered the command:

 

            unsigned char c = -712;

 

            and then entered the command:

 

            printf("The numberic value of c is %d representing the character %c\n",c,c);

 

     What would be produced, and why??

 

     SEE SOLUTION