Test Your Knowledge (Ch 2)

The following questions are based on what we have learned so far in Chapter 2 – Behind the Scenes. To test your understanding, try answering the following questions. The explanations are also provided to each question so you can always check the correctness of your answers. All the best 👍


Question 1

What are the different stages of program execution?

preprocessing, compiling, linking
input, process, output
preprocessing, compiling, assembling, linking
None of the above
explanation

Preprocessing, compiling, assembling, and linking are the four stages of program execution.

Question 2

Who is responsible to link the declaration of the functions with the definitions?

Loader
Preprocessor
Compiler
Linker
explanation

Linker is responsible to link the declaration of the functions with the definitions.

Question 3

State True or False.
The getch() function takes a single character at a time and waits until the user feeds in the character to it.

True
False
explanation

Yes, the getch() function waits for the user to enter a character. It is a popular technique used to stick the console window on the screen.

Question 4

The output of the preprocessor is _________?

expanded source code
assembly code
machine code
object code
explanation

The output of the processor is the expanded source code.

Question 5

Which of the following is NOT done by the preprocessor?

Removal of comments
Expansion of header files
Conversion of source code to machine code
Expansion of macros
explanation

The Preprocessor never converts source code to machine code.

Question 6

Fill in the blank
A macro is a piece of code which is replaced by preprocessor with the macro’s _______

size
value
definition
declaration
explanation

The Preprocessor never converts source code to machine code.

Question 7

Which flag is used to stop the assembler from taking the assembly code?

-S
-E
-C
None of the above
explanation

Recall the following command that gives the assembly code as an output generated by the compiler:

gcc -S add.i -o add.s
Question 8

What is the extension of the object file?

.s
.exe
.o
None of the above
explanation

the extension of the object file is .o.

Question 9

Consider the following program with the line numbers:

1. #include <stdio.h>
2. #define MAX 1000
3. 
4. int main() {
5.     // print the maximum value
6.     printf(“Maximum value allowed is %d”, MAX);
7.     // return zero
8.     return 0;
9. }

Which lines in the above program are changed or removed by the preprocessor?

Lines 1, 2, and 5
Lines 1, 2, 5, and 9
Lines 1, 2, 5, and 7
Lines 1, 2, 5, 6, and 7
explanation

The preprocessor will completely remove lines 1, 2, 5, and 7 and it will update line 6 by replacing MAX with 1000. The resultant program looks like the following:

int main() {
    printf(“Maximum value allowed is %d”, 1000);
    return 0;
}
Question 10

Fill in the blank
Assembler converts assembly code to _______

executable
object code
source code
None of the above
explanation

Assembler converts assembly code to object code.

Your score is out of



Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *

Thank you for choosing to leave a comment. Please be aware that all comments are moderated in accordance with our policy. For more information, please review our comments policy. Rest assured that your email address will not be shared with anyone. Kindly refrain from using keywords in your comment. Let’s maintain a respectful atmosphere and engage in meaningful conversations.