Quizes Flashcards
Review past quizzes
Which of the following tasks are performed by the C preprocessor? Select all answers that seem correct.
- Include the contents of other files within a C program
2. Modify the C program
What is assembly language?
A human-readable form of machine language
What is the purpose of the linker?
Combine object files into an executable file
What does a compiler do? Select all answers that seem right.
Translates a computer program into machine language
Checks a program for syntax errors
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]?
Answer: “dick”
name[0] = "./prog4" name[1] = "tom" name[2] = "dick" name[3] = "harry"
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?
Answer:
if (days > 3) days = 3;
all variable DAYS is replaced with 3
Given the C declaration:
char name[ ] = “egbert”;
what is the value of name[4]?
Answer:
‘r’
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.
Answer:
0
What is the purpose of a header file in C programming?
It provides declarations of functions defined in a separate C module
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?
answer:
8 bits = char = 1 byte
bits pattern stored in the computer’s memory in the space
allocated for x = 0001100
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?
Answer:
16
n = 0 -- text[0] = 'C' . . n =15 --text[15] = '!' n = 16 -- text[16] = 0
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?
answer:
char = 8 bits
0000 1100
2s complement 1111 0011 \+ 1 ------------- 1111 0100
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?
answer: 234
char = 8 bits
0001 0110
2s complement 1110 1001 \+ 1 ------------- 11101010
128 + 64 +32+10 = 234
alternatively,
11101010
258 - 22 = 236
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?
answer:
4-byte number = 32 bits
largest value for unsigned int 2^32 -1
What is the decimal value of the hexadecimal number 2E?
answer:
0x2E => 0010 1110 => 32+14 = 46