Programming Languages [ch. 6]
A subrange type is a subsequence of an ordinal type. Select the allowable sequences.
A. (12,13,..,18,19)
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
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
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. D. A C++ reference variable is an alias.
Which of the following statements are true concerning union types?
A. A union may store different types in the same location at different times. C. A discriminated union enforces type checking with a tag (type indicator). D. The purpose of a union type is to save space.
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.
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.
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.
Which C structure supports an array of elements of varying sizes? (a "jagged array")
A. a static array of void pointers
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;
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
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
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
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
Which of the following statements are true? An area allocated in the heap
A. with no associated pointer is a memory leak. C. with multiple associated pointers has cross-linked pointers. D. can have multiple associated pointers - they are called aliases.
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}
Under binary coded decimal encoding, the encoding of 137 is what?
B. 0001 0011 0111
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
B. 9 2 6 7 5 3 4 8 1
Which approach to garbage collection is more efficient but when you need memory the most, this approach is the least desirable?
B. lazy approach
What type of array allocation is performed in this C++ code? cin >> size; int sd_array[size];
B. stack-dynamic
Select the correct statement concerning this C code: void dbl_ptrs(int** dptr) { int *tmp_ptr = *dptr;
B. tmp_ptr now holds the address of an integer variable
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);
C. 1
Select the true statements.
C. An example of an associative array is a hash table. D. An associative array enhances code writeability.
Strings in Perl are scalar types. Since Perl uses dynamic typing, what is true?
C. both A & B
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;
C. both statements are true
Select the true statement.
C. both statements are true
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]));
C. fixed heap-dynamic
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
D. 5
What type of array allocation is performed in this C code? scanf ("%d",&size); int * h_array = (int *) malloc(sizeof(int[size]));
D. heap-dynamic
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
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
An enumeration type may begin with any integral value.
True