CMPS 350 HW 6 - Data Types

You must 'check' your answer on each question or your score will not be recorded.
01. If the 'int' data type is implemented in 4 bytes, with negative integers
    stored as the two's complement of the positive integer, what is -3?
    A. 11111111111111111111111111111101
    B. 11111111111111111111111111111010 
A B
02. In Perl strings can be any length and the size can change at runtime. What
    is true regarding Perl's memory management for this valid code?

      sub test {
           my str;
           $str = <stdin>; // user types in hello 
           $str = <stdin>; // user types in the gettyburg address
           $str = <stdin>; // user types in hi
      }
A. Perl dynamically allocates memory from somewhere three times.
B. Since strings are scalars, Perl allocates enough memory on the stack one 
   time only to hold the largest possible string.
C. Perl dynamically allocates memory on an as-needed-basis for $str as the user
   is typing - thus when user types in 'hi' no new allocation is needed.
A B C
03. Strings in Perl are scalar types. Since Perl uses dynamic typing, what is 
    true? 
A. If Perl sees a number when it expects a string, it implicitly converts the 
   number into a string type; e.g. 25 becomes "25".
B. If Perl sees a string when it expects a number, it implicitly converts the 
   string into a number type of arbitrary value; e.g. "hello" becomes 0.
C. both A & B 
A B C
04. Select the true statements.
    A. An ordinal number reflects the position of that number in a set. 
    B. A range of integers; e.g. (2..20) is an ordinal set.
    C. An ordinal set is countable.
    D. An ordinal set can skip a number; e.g., {1,2,3,7,8,9} is an ordinal set. 
A B C D
05. Select the true statements.
    A. An enumeration type must be mapped to a set of ordinal numbers.
    B. All possible values in an enumeration type must be named constants.
    C. The first value in an enumeration type must be 0.
    D. The default first value in an enumeration type in C is 1.
A B C D
06. A subrange type is a subsequence of an ordinal type. Select the allowable
    sequences.
    A. (12,13,..,18,19)  
    B. (15.5,..,19.5)
    C. both A and B
A B C
07. An enumeration type may begin with any integral value. 
T F
08. What type of array allocation is performed in this C code? (malloc is the
    operator in C to allocate memory from the heap)

         int *i_array = (int *) malloc(sizeof(int[5]));  

   A. fixed stack-dynamic
   B. stack-dynamic
   C. fixed heap-dynamic 
   D. heap-dynamic  
A B C D
09. What type of array allocation is performed in this C code?
        scanf ("%d",&size);
        int * h_array = (int *) malloc(sizeof(int[size])); 

   A. fixed stack-dynamic
   B. stack-dynamic
   C. fixed heap-dynamic
   D. heap-dynamic  
A B C D
10.What type of array allocation is performed in this C++ code?

       cin >> size;
       int sd_array[size];   

   A. fixed stack-dynamic
   B. stack-dynamic
   C. fixed heap-dynamic
   D. heap-dynamic  
A B C D
11.What type of array allocation is performed in this C code?
       void funA() {
          int i_array[5] = {1,2,3,4,4};   

   A. fixed stack-dynamic
   B. stack-dynamic
   C. fixed heap-dynamic
   D. heap-dynamic arrays 
A B C D
12. Select the true statements.
   A. The elements in an associative array have an implicit order.
   B. An associative array is indexed by an ordinal type.
   C. An example of an associative array is a hash table.
   D. An associative array enhances code writeability.
A B C D
13.In these statements, which is an example of an aggregate constant in C?
           int list [] = {4, 5, 7, 83}    
           char name[20] =  "sam spade";

   A. {4,5,7,1}        B. "sam spade"    
    
A B
14. Which of the following is a listing in row major order of the matrix shown
    here:

      9 2 6 
      7 5 3 
      4 8 1 

   A. 9 7 4 2 5 8 6 3 1               B. 9 2 6 7 5 3 4 8 1  
A B
15. Which of the following statements are true concerning union types?
 
A. A union may store different types in the same location at different times.
B. A free union allows more than one of the specified type values to be stored 
   at the same time.
C. A discriminated union enforces type checking with a tag (type indicator).
D. The purpose of a union type is to save space. 
A B C D
16. Which of the following statements are true? An area allocated in the heap 

A. with no associated pointer is a memory leak.
B. with no associated pointer is a dangling pointer.
C. with multiple associated pointers has cross-linked pointers.
D. can have multiple associated pointers - they are called aliases. 
A B C D
17. Select the true statements.
    A. A C++ reference variable is bound to the memory location of the variable 
       it references.
    B. You can never get a "dangling reference" with C++'s reference variables.
    C. You can explicitly dereference a C++ reference variable.
    D. A C++ reference variable is an alias. 
A B C D
18. Select the true statement.
    A. In eager garbage collection, reclamation is done in stages throughout 
       program execution. 
    B. In lazy garbage collection, reclamation occurs only when the list of 
       variable space is completely empty.
    C. both statements are true 
A B C
 
19. Which approach to garbage collection is less efficient but gives you have 
    the maximum amount of available memory at any given time?
    A. eager approach
    B. lazy approach   
A B
20. Which approach to garbage collection is more efficient but when you need 
    memory the most, this approach is the least desirable?
    A. eager approach
    B. lazy approach  
A B
21. Select the correct statement concerning this C code:

   void dbl_ptrs(int** dptr) {
      int *tmp_ptr = *dptr;  
   
   A. tmp_ptr now holds the address of a pointer variable 
   B. tmp_ptr now holds the address of an integer variable
   C. tmp_ptr now holds an integer value   
A B C
22. What is displayed on the screen in the following C code?

     bits.b = 4;   // size 4 bit field
     bits.b = 5;   // size 4 bit field
     printf("%d", bits.a | bits.b);   // | is bitwise or 

     A. 0      B. 1     C. 4     D. 5 
A B C D
23. In the IEEE standard, single precision floating point numbers are
    represented in the format s * 2^e, where 'e' is the stored value of the
    exponent - 127, and 's' is 1 + the stored value of the fraction. Under
    this encoding, what is the decimal value of the following?

   0    10000100  01000000000000000000000
   -    --------  -----------------------
   sign exponent  fraction
   1     8 bits   23 bits

   A. 1.25 * 2^5          B. 1.4 * 2^-5       C. 1.5 * 2^4     
A B C
24. What will be displayed on the screen in the following C code?
 
    struct Bits {
       unsigned int a:1; // bit field of size 1 bit
       unsigned int :0 ; // unnamed bit field of size 0 forces c to be aligned
       unsigned int c:2; // named bit field of size 2
    } bits;
    bits.a = 5;  
    printf("bits.a: %d \n", bits.a);
  
   A. 5       B. 0      C. 1  
A B C
25. The C code below declares a 2x3x4 array of ints. Complete the statement
    to initialize each cell in the cube with its offset into the array. Recall
    that C stores 3-dimensional arrays in row-column-depth order.

 /* 3-dimen arrays are in x,y,z order; e.g. row,col,depth */
  int cube[2][3][4];
  int x,y,z;
  for (x = 0; x < 2; x++)
     for (y = 0; y < 3; y++)  
        for (z = 0; z < 4; z ++) 
           // which statement will insert the offset?
        }
      }
   A. cube[x][y][z] = (x*(3*4))+(y*4)+ z;
   B. cube[x][y][z] = (z*(2*3))+(y*4)+ x;
   C. cube[x][y][z] = (x*(2*3))+(y*4)+ z;  
A B C
26. Under binary coded decimal encoding, the encoding of 137 is what?
    A. 001 011 111       B. 0001 0011 0111      C. 1000 1001 
A B C
27. Which C structure supports an array of elements of varying sizes? (a 
    "jagged array")
    A. a static array of void pointers
    B. an array of union types
    C. both are correct  
A B C
 
28. Select the true statement concerning this Ada code. Ada includes implicit 
    index boundary checking and the coder specifies index range.

       type AN_ARRAY is array(1..10) of INTEGER;   
       myArray : AN_ARRAY;
       ...
       myArray(99) := 0;

    A. The code will compile but raise a CONSTRAINT_ERROR at runtime.
    B. The code will compile but will generate with a compile-time warning.
    C. both statements are true  
A B C
29. C employs eager garbage collection and calls to malloc always allocate 
    multiple bytes of storage in contiguous memory locations. Recurrent calls
    to fun() will cause heap fragmentation.

    void fun(){
     char *a_char = (char *) malloc(sizeof(char));
     char *a_char2 = (char *) malloc(sizeof(char));
     free a_char;
     double *a_dbl = (double *) malloc(sizeof(double));
     free a_dbl;
     free a_char2;
    }
T F
30. If you change the size of a static array of integers in C (from 50 to 100 
    integers for example), and recompile, the size of the executable file will 
    increase.
T F
31. What happens at Line 3 in the following C++ code? 
     int stuff[2] = {5,10};
     int &iref = stuff;
     iref++;   // line 3 

   A. stuff[0] is incremented from 5 to 6
   B. iref is incremented to point to stuff[1]  
A B
32. What do these regexes match?

    A.  /^[A-Za-z][A-Za-z\d]+/   
    B.  /[yY][eE][sS]/
    C.  /[0-9a-fA-F]/	          
    D.  /[^0-9]{4}/           

A. lines starting with a letter followed by one or more letters or digits 
B. the first occurrence of 'yes' in any possible upper/lowercase variation  
C. the first occurrence of a word starting with a digit followed by two
   letters a-f or A-F
D. lines that start with a digit followed by 4 more digits
A B C D

  Right: Wrong: Percent: (Must be 100% for credit)

Errors:

Name (first name only): Sleipnir Username: 3-digit ID: