Quizes Flashcards

Review past quizzes

1
Q

Which of the following tasks are performed by the C preprocessor? Select all answers that seem correct.

A
  1. Include the contents of other files within a C program

2. Modify the C program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is assembly language?

A

A human-readable form of machine language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of the linker?

A

Combine object files into an executable file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does a compiler do? Select all answers that seem right.

A

Translates a computer program into machine language

Checks a program for syntax errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A C program, in a file called prog4.c has a main() function with heading

int main(int num, char *name[ ]);

The program is compiled and run, using the following commands:

gcc -Wall -o prog4 prog4.c
./prog4 tom dick harry

Within the main() function, what is the value of name[2]?

A

Answer: “dick”

name[0] = "./prog4"
name[1] = "tom"
name[2] = "dick"
name[3] = "harry"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

define DAYS 3

A C program contains the following line:

and, further on in the same file, the following statement:

if (days > DAYS) days = DAYS;

Which of the following is the C statement that is actually compiled?

A

Answer:

if (days > 3) days = 3;

all variable DAYS is replaced with 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given the C declaration:

char name[ ] = “egbert”;

what is the value of name[4]?

A

Answer:

‘r’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the C declaration:

char name[ ] = “egbert”;

what is the value of name[6]?

Note the 0 in the answers is a zero, not an upper-case O.

A

Answer:

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of a header file in C programming?

A

It provides declarations of functions defined in a separate C module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If in a C program, x is declared as

char x = 12;

What pattern of bits is stored in the computer’s memory in the space allocated for x?

A

answer:

8 bits = char = 1 byte

bits pattern stored in the computer’s memory in the space
allocated for x = 0001100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Given the following C statements:

char text[20] = “CSCI_247 is fun!”;
int n;
for (n=0; text[n]; n++) ;

What is the value of n after these statements?

A

Answer:

16

n = 0  -- text[0] = 'C'
.
.
n =15 --text[15] = '!' 
n = 16 -- text[16] = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If in a C program, x is declared as

char x = -12;

What pattern of bits is stored in the computer’s memory in the space allocated for x?

A

answer:

char = 8 bits
0000 1100

2s complement
 1111 0011 
\+           1
-------------
  1111 0100
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If in a C program, x and y are declared as

char x = -22;
unsigned char y = (unsigned char) x;

The use of (unsigned char) in the initialization of y is a type cast. It enables the bits representing x to be viewed as an unsigned char. No bits are changed, the value of y is simply a different interpretation of the same bits.

What is the decimal value of y?

A

answer: 234

char = 8 bits

0001 0110

2s complement
1110 1001
\+           1
-------------
11101010

128 + 64 +32+10 = 234

alternatively,
11101010
258 - 22 = 236

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If in a C program, x is declared as

unsigned int x;

Assuming that int is a 4-byte number, what is the largest value that x may contain?

A

answer:

4-byte number = 32 bits

largest value for unsigned int 2^32 -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the decimal value of the hexadecimal number 2E?

A

answer:

0x2E => 0010 1110 => 32+14 = 46

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the hexadecimal representation of the binary number 0111010100101100?

A

answer:

0111 0101 0010 1100
0x752C

17
Q

A short int in C is stored on a little-endian computer in 2 bytes as:

10110011 00111010

What is the hexadecimal value of this short int?

A

answer:

2 bytes = 16 bits

1011 0011 0011 1010
B 3 3 A

littlen endian => 0x3AB3

18
Q

In class this week, we saw that the decimal number 12345678 is the same as the hexadecimal number 0x00BC614E.

For a 2’s-complement representation, what is the hexadecimal value of the decimal number -12345678?

A

answer: 0xFF439EB2

In class this week, we saw that the decimal number 12345678 is the same as the hexadecimal number 0x00BC614E.

For a 2’s-complement representation, what is the hexadecimal value of the decimal number -12345678?

solution:
0000 0000 1011 1100 0110 0001 0100 1110

2s complement
1111 1111 0100 0011 1001 1110 1011 0001 + 1
1111 1111 0100 0011 1001 1110 1011 0010

0xFF439EB2

19
Q

Given the following C statements:

int a[6] = {1, 2, 3, 4, 5, 6};
for (int i = 1; i < 6; i++) a[i] = a[i] + a[i-1];

What is the value of a[4]?

A

answer:

15

20
Q

A C program contains the statement:

if (number&raquo_space; 31) count++;

If number is a 32-bit signed integer, what does it mean if the expression
number&raquo_space; 31
is true?

A

answer: negative number

number&raquo_space; 31

let number =7 = 0111

00000000 00000000 00000000 00000111 &laquo_space;31

means shift arithmetically to the right 31 bits

11111111 11111111 11111111 11111110

21
Q

If a C program has a variable declared as:

char number = somevalue;

which expression would determine the integer value of the least significant 5 bits of number?

A

answer:

number & 0x1F

22
Q

If a C program has a variable declared as:

char number = somevalue;

which expression will always be false whenever number is even?

A

number & 0x01

example:
number = 2

0000 0010 &amp; 0000 0001
-----------------    0000 0000 => false

number = 3
0000 0011

23
Q

How is the fraction 17/16 exactly represented as a binary number?

A

answer:

0. 010001

24
Q

Suppose we have a 8-bit representation for fixed-point numbers, in which the first 4 bits specify the integer part of the number, in 2’s complement format and the second 4 bits specify the fractional part, as a binary fraction. The binary point is implicitly between the two half-bytes.

If the 8 bits for a value are:

01011010

what is the fixed-point number represented by those bits?

A

answer: 5 5/8

8-bit floating point

0101 1010

1/2 +1/8 = 5/8 for fraction
5 for exponent
therefore, 5 5/8

25
IEEE single-precision floating-point format uses 32 bits, with one bit for the sign, 8 bits for the exponent and 23 bits for the fraction. The smallest positive number that can be represented in this format is 00000000000000000000000000000001 What value does this bit pattern represent?
answer: 32-bit 8 bit for exp 23 bits for frac 0 00000000 00000000000000000000001 Denorm Bias = 2^7 - 1= 127 E = 1-127 = -126 M = f = 2^-23 V = 1 x 2^-23 x 2^-126 V = 2^-149
26
IEEE single-precision floating-point format uses 32 bits. with one bit for the sign, 8 bits for the exponent and 23 bits for the fraction. What is the exact representation of the value 1 in this format?
answer: 32-bit 8 -exp bit 23 -frac bit 00111111100000000000000000000000
27
Suppose we have an 8-bit floating-point number that follows the same rules as the IEEE floating-point numbers but has one sign bit, 3 bits for the exponent and 4 bits for the fraction. With this format, what is the numeric value of the following bit sequence? 01011101
answer: 8-bit 0 101 1101 => normalize Bias = 3 E = 5-3 = 2 M =1+ (3/4+1/16) = 1+13/16 = 29/16 V = 1 x 29/16 x 2^2 = 29/4
28
For the same floating-point number format described in Question 8: one sign bit, 3 bits for the exponent and 4 bits for the fraction, what is the numeric value of the following bit sequence? 00001101
Answer: 0 000 1101 => Denorm ``` Bias = 3 E = 1 - 3 = -2 M = f = 13/16 V = 1 x 13/16 x 2^-2 = 13/64 ```
29
For the same floating-point number format described in Question 8: one sign bit, 3 bits for the exponent and 4 bits for the fraction, what bit sequence exactly represents the numeric value LaTeX: \frac{1}{64} 1 64 ?
answer 00000001