This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1A computer program that converts an assembly language program into equivalent machine language program is called
Option B
A computer program that converts an assembly language program into its equivalent machine language is called an assembler.
Assembly language uses symbolic instructions like MOV, ADD, SUB etc. called mnemonics, which are easier for humans to understand but must be translated into binary machine code for the computer to execute.
Q: 2Generally, the syntax errors are occurred during?
Option A
Syntax Errors occur during Compile Time because the compiler checks the code for correct syntax before converting it into machine code. If there is any violation of syntax rules like missing comma, missing semicolon, missing quotes, wrong brackets, or misspelled keywords, the compiler immediately reports the error and does not allow the program to run until these errors are fixed.
Q: 3During the compilation process, which stage is responsible for grouping characters into meaningful sequences called tokens?
Option B
When a compiler translates source code written by a programmer into a form that a computer can actually execute, this translation process happens through several distinct stages, each responsible for a different part of the overall job.
During compilation, Lexical Analysis is the first phase of the compiler. It reads the source program character by character and groups them into meaningful sequences called tokens.
For example, in the statement int num=55;, the lexer identifies int as a keyword, num as an identifier, = as an operator, 55 as a constant, and ; as a separator.
Compilation Phases:
| Phase | Alternative Name | Description | Input | Output |
|---|---|---|---|---|
| Lexical Analysis | Scanning / Lexing | Reads the source program character by character and groups them into meaningful tokens. | Source Code | Tokens |
| Syntax Analysis | Parsing / Syntactic Analysis | Checks whether the sequence of tokens follows the grammar and syntax of the programming language. | Tokens | Parse Tree / Syntax Tree |
| Semantic Analysis | Semantic Checking | Checks the meaning and logical consistency of the program, such as type compatibility, declarations, and scope. | Syntax Tree | Annotated Syntax Tree |
| Intermediate Code Generation | IR (Intermediate Representation) Generation | Converts the analyzed program into a machine-independent intermediate representation. | Annotated Syntax Tree | Intermediate Code |
| Code Optimization | Code Optimization Phase | Improves the intermediate code to make the program more efficient, such as reducing unnecessary operations. | Intermediate Code | Optimized Intermediate Code |
| Code Generation | Target Code Generation | Converts the optimized intermediate code into target machine/assembly code. | Optimized Intermediate Code | Target Code |
Q: 4Which one of the following is not performed during the compilation of a program?
Option C
Compilation is the process of converting source code into machine code. It can do things like syntax checking, type checking, and keeping track of symbols such as variables and functions in the symbol table.
But Dynamic Memory Allocation happens at run time, not during compilation. Memory is requested while the program is executing.
Q: 5Which one of the following statements is incorrect?
Option C
A compiler, assembler, and interpreter are all language processing tools (translator), but they work differently.
A compiler reads the entire source program at once, checks it for errors, and then converts it into machine code.
An assembler takes an assembly language program as input and converts it into machine code.
However, an interpreter does not execute the complete source code at once like compiler. Instead, it reads and executes the program line by line, stopping whenever it finds an error.
Q: 6A compiler is a translating program which
Option D
A compiler translates high-level language source code into machine language, processing the entire source program at once to produce an executable machine language program.
Unlike interpreters, compilers are not involved in the execution phase, the compiled program runs independently.
Q: 7A computer program that converts a high-level language program into an equivalent machine language program is called
Option B
A high-level language like C, C++, Java is human-readable. A compiler is a special program that translates this high-level source code into an equivalent machine language program that the CPU can execute.
| Translator | Description | Translation Method | Example Languages |
|---|---|---|---|
| Compiler | Converts entire program from high-level languages to machine code at once. | Whole program translated before execution. | C, C++, Java |
| Interpreter | Converts and executes program one line at a time from high-level language. | Line-by-line translation and execution. | Python, JavaScript, Perl |
| Assembler | Converts assembly language (low-level) to machine code. | One-to-one mnemonic to machine code translation. | x86 Assembly, ARM Assembly |
Q: 8The output of lexical analysis is a
Option D
The process of converting a high-level program into machine code is done in multiple phases of a compiler. Each phase performs a specific task to transform the source code step by step into machine code.
1) Lexical Analysis.
2) Syntax Analysis or Parsing.
3) Semantic Analysis.
4) Intermediate Code Generation.
5) Code Optimization.
6) Code Generation.
In the compilation process, Lexical Analysis is the first phase of a compiler. It takes the source code as input and breaks it into smaller units called tokens such as keywords, identifiers, operators, and constants.
The output of lexical analysis is therefore a stream or set of tokens, which is then passed to the next phase Syntax Analysis.
| Phase | Input | Output | Description |
|---|---|---|---|
| Lexical Analysis | Source Code | Set of Tokens | Breaks source code into small units called tokens (keywords, variables, operators). |
| Syntax Analysis | Tokens | Parse Tree | Checks grammar of the program and builds a structured tree representation. |
| Semantic Analysis | Parse Tree | Annotated Parse Tree | Checks meaning (type checking, variable declaration, etc.). |
| Intermediate Code Generation | Annotated Parse Tree | Intermediate Code | Converts program into a machine-independent intermediate form. |
| Code Optimization | Intermediate Code | Optimized Code | Improves code to make it faster and efficient. |
| Code Generation | Optimized Code | Target/Object Code | Converts optimized code into machine (binary) code for execution. |
Q: 9When the rules of the programing language are not followed it gives ______ errors.
Option A
Every programming language has a set of grammatical rules called Syntax Rules. A program must follow these rules properly, otherwise, the compiler or interpreter generates a syntax error.
There are some examples when syntax errors occur:
| Error Type | Description |
|---|---|
| Syntax Error | Occurs when language grammar rules are violated. |
| Logical Error | Program runs but produces wrong output. |
| Run Time Error | Occurs during program execution. |
Q: 10The errors that can be pointed out by compiler are?
Option A
A compiler checks the program for grammatical correctness according to the rules of the programming language. Errors related to incorrect syntax are detected by the compiler at compile time.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.