Q: 1 The meaning of each ________is fixed. We can simply use them for its intended meaning.
Identifier
Constant
Variable
Keywords
[ Option D ]
In C programming, keywords are special words that have a fixed and predefined meaning, decided by the language itself. We cannot change their meaning, nor can we use them as identifiers.
| Related to Primitive Data Types | Related to Control Statement | Related to Storage Classes | Related to User-Defined Data Type | Other Purpose |
|---|---|---|---|---|
| int | if | auto | struct | const |
| char | else | static | union | sizeof |
| float | switch | register | enum | volatile |
| double | case | extern | typedef | |
| short | default | |||
| long | break | |||
| signed | continue | |||
| unsigned | goto | |||
| void | do | |||
| while | ||||
| for | ||||
| return |
Q: 2
Match the following C statements with the correct number of tokens:
| List—I (C Statements) | List—II (Number of Tokens) |
|---|---|
| (i) int a = 10; | (P) 5 |
| (ii) printf("Hi Suresh"); | (Q) 6 |
| (iii) a = b + c; | (R) 9 |
| (iv) x = y++ + --z; | (S) 8 |
(i)—(P), (ii)—(Q), (iii)—(S), (iv)—(R)
(i)—(Q), (ii)—(Q), (iii)—(Q), (iv)—(R)
(i)—(P), (ii)—(P), (iii)—(Q), (iv)—(R)
(i)—(P), (ii)—(P), (iii)—(Q), (iv)—(S)
[ Option D ]
Q: 3 Count the number of tokens in following C statement?
printf("Suraku Academy");
5
8
7
3
[ Option A ]
| Element | Type | Token Count |
|---|---|---|
| printf | Identifier | 1 |
| ( | Separator | 1 |
| "Suraku Academy" | String | 1 |
| ) | Separator | 1 |
| ; | Separator | 1 |
So, total tokens are 5.
Q: 4 Which of the following is not a valid variable name in most programming languages?
myVariable
123Variable
_myVariable
More than one of the above
[ Option B ]
A variable is a named location in memory that is used to hold or store the value. The value of variable can be modified in the program by the instruction. The variable names must follow the rules of identifiers.
RULES FOR WRITING IDENTIFIERS:
| Variable Name | Result | Why? |
|---|---|---|
| myVariable | Valid. | Starts with a letter, follows identifier rules. |
| 123Variable | Invalid. | Variable names cannot start with digits. |
| _myVariable | Valid. | First character is underscore. Alphabets and underscore is allowed as the first character. |
Q: 5 During entire program execution the value of ___________ cannot be changed.
Variable
Constant
Literals
Function
[ Option B ]
In programming like C, we store information using variables or other fixed items. Some values need to stay the same forever during the whole program run, like math number PI, number of days in a week, or maximum speed limit etc.
A constant is a value that is fixed and cannot be changed during the execution of a program. Constants are used when we want to make sure a value remains the same throughout the program.
#include <stdio.h>
int main()
{
int age = 29;// Variable.
printf("Age : %d ", age);
age = 34; // Changing value of variable.
printf("Updated Age : %d ", age);
const float PI = 3.14;// Constant.
printf("Value of PI: %.2f ", PI);
PI = 3.1415; // Error. Cannot change a constant.
return 0;
}
Q: 6 Which compiler phase receives tokenized output?
Lexical Analyser
Parser
Pre-processor
Assembler
[ Option B ]
In the compilation process, the Lexical Analyzer is the first phase that reads the source program and converts it into a sequence of tokens (such as keywords, identifiers, operators, and symbols). These tokens form the tokenized output of the lexical analyzer.
The Parser (Syntax Analyzer) is the next phase of the compiler, and it receives these tokens as input. The parser checks whether the tokens follow the grammatical structure of the programming language and constructs a Parse Tree or Syntax Tree. Therefore, the compiler phase that receives the tokenized output is the Parser.
Q: 7 A comment:
Is a note that can be put into the source code
Is ignored by the compiler
Starts with the /* and end with the */ character pair
All of the above
[ Option D ]
A comment is used to add notes or explanations within the source code to make it easier for humans to understand. Comments are ignored by the compiler, so they do not affect the execution of the program.
In C, a multi-line comment starts with /* and ends with */. Single-line comments can also be written using //.
Q: 8 In context of C language, the word ‘if’ is a
Conjunction
Keyword
Identifier
Both (a) and (b)
[ Option B ]
In C language the if is keywords. A keyword is a reserved word that has a predefined meaning in the language and cannot be used as an identifier. The if is used for decision-making.
Q: 9 The backslash constant ‘\r’ can be used for? Choose best answer.
Move cursor back to one position
Move cursor top of console window
Move cursor beginning to current line
Move cursor beginning to previous line
[ Option C ]
The backslash constant \r is called the carriage return. It moves the cursor back to the beginning of the current line, without moving to a new line or erasing any existing content. This allows the next characters to overwrite the existing characters on the same line.
Q: 10 Which of the following statement(s) is/are correct?
I. Keywords are those words whose meaning is already defined by Compiler.
II. Keywords cannot be used as variable name.
III. There are 32 keywords in ANSI C.
IV. C keywords are also called as reserved words.
I and II only
II and III only
I, II and IV only
I, II, III and IV
[ Option D ]
Must Know:
| Keyword | Description |
| _Bool | Represents Boolean data type. In C, 0 (zero) is treated as false and any non-zero value is treated as true. |
| _Complex | Represents complex numbers (real + imaginary). |
| _Imaginary | Represents imaginary numbers (pure imaginary part). |
| inline | Suggests the compiler to expand the function inline to reduce call overhead. |
| restrict | A pointer qualifier that tells compiler the pointer is the only way to access data. |
Q: 11 Which of the following is a phase of a compilation process?
Lexical Analysis
Code Generation
Static Analysis
Both (A) and (B)
[ Option D ]
The compilation process converts source code into machine code through several phases. Two important phases are Lexical Analysis and Code Generation, both of which are essential parts of a compiler.
Lexical Analysis is the first phase where the source code is broken into tokens such as keywords, identifiers, and operators. It removes unnecessary characters like spaces and comments and prepares the input for the next phase.
Code Generation is the final phase where the compiler produces target code (machine code) from the processed input. It ensures that the output is optimized and executable by the system.
Q: 12 What will be the output of the following program?
#include <stdio.h>
int main()
{
int main=55;
printf("%d",main);
return 0;
}
Compile-Time Error
Run-Time Error
55
1
[ Option C ]
In C programming, identifiers can be the same as long as they belong to different scopes.
In this program, main is the name of the function, but inside the function, a local variable is declared with the same name main and assigned the value 55.
This is valid because the variable exists only within the functions block and does not conflict with the function name.
Q: 13 Count the number of tokens in following C statement?
int num=10;
4
5
3
6
[ Option B ]
| Element | Type | Token Count |
|---|---|---|
| int | Keyword | 1 |
| num | Identifier | 1 |
| = | Operator | 1 |
| 10 | Constant | 1 |
| ; | Separator | 1 |
So, total tokens are 5.
Q: 14 The ASCII code for character ‘A’ (Capital letter A) is
65
55
88
64
[ Option A ]
ASCII (American Standard Code for Information Interchange) is a character encoding standard used to represent characters as numeric values in computers.
In the ASCII table:
Therefore, the ASCII value of ‘A’ = 65.
Q: 15 The keyword ‘const’ keeps the value of a variable _________.
Mutable
Variant
Constant
Both (b) and (c)
[ Option C ]
The keyword const is used when we want to make sure that the value of a variable cannot be changed after it is assigned. When a variable is declared with const, it becomes a constant, meaning its value remains the same throughout the program.
Q: 16 The header file necessary to do mathematical calculation.
alloc.h
stdio.h
string.h
math.h
[ Option D ]
In C language, the header file math.h contains the prototypes of mathematical functions such as sqrt(), pow(), sin(), cos(), and log(). By including this header file at the beginning of a program using #include<math.h>, we can use these predefined functions to perform various mathematical calculations.
Q: 17
Match the following C statements with the correct number of tokens:
| List—I (C Statements) | List—II (Number of Tokens) |
|---|---|
| (i) int x = 5, y = 10; | (P) 9 |
| (ii) if(a>=b) | (Q) 6 |
| (iii) printf("Hello World"); | (R) 5 |
| (iv) a = b * (c + d); | (S) 10 |
(i)—(P), (ii)—(Q), (iii)—(R), (iv)—(S)
(i)—(P), (ii)—(R), (iii)—(Q), (iv)—(S)
(i)—(P), (ii)—(R), (iii)—(R), (iv)—(P)
(i)—(P), (ii)—(Q), (iii)—(Q), (iv)—(P)
[ Option A ]
| Statement | Tokens | Total |
|---|---|---|
| int x = 5, y = 10; | int, x, =, 5, ,, y, =, 10, ; | 9 |
| if(a>=b) | if, (, a, >=, b, ) | 6 |
| printf("Hello World"); | printf, (, "Hello World", ), ; | 5 |
| a = b * (c + d); | a, =, b, *, (, c, +, d, ), ; | 10 |
Q: 18 The name of identifier in C language must be starts from alphabets or______?
# (hash)
* (asterisk)
_ (underscore)
None of these
[ Option C ]
Combination of letters becomes an identifier. Identifiers are used for give the names of various program elements like variables, array, functions, structure etc.
RULES FOR WRITING IDENTIFIERS:
Q: 19 What will be the output of the following program?
#include <stdio.h>
int main()
{
char ch=128;
printf("%d",ch);
return 0;
}
128
-128
0
127
[ Option B ]
In C, a char usually takes 1 byte and by default it is signed, with range -128 to 127. The value 128 is outside this range.
When char ch=128; is assigned, overflow occurs. Due to 2’s complement representation, the value wraps around and becomes -128. Therefore, printf("%d", ch); prints -128.
Q: 20 The number of tokens in the following given C language code?
switch(choice)
{
case 1 : b=c*d; break;
default : b=b++; break;
}
27
26
29
24
[ Option B ]
A Token is the smallest meaningful part of a program. It is a group of characters that the compiler treats as a single unit. For example, keywords (int), variable names (a), operators (+), constants (5), and symbols (;) are all tokens.
Lexical Analysis is the first phase of a compiler, also called a Scanner. In this phase, the compiler reads the program line by line and breaks it into tokens. It removes Extra Spaces (Whitespace Character) and Comments and converts the high-level program into a sequence of tokens.
This token sequence is then passed to the next phase (Syntax Analysis) for further processing.
Step-by-Step Token Counting:
| Statement | Tokens | Total |
|---|---|---|
| switch(choice) | switch ( choice ) | 4 |
| { | { | 1 |
| case 1 : b=c*d; break; | case 1 : b = c * d ; break ; | 11 |
| default : b=b++; break; | default : b = b ++ ; break ; | 9 |
| } | } | 1 |
| Total | 26 | |
Q: 21 The __________ cannot be used as an identifier.
Keyword
Variable
Constant
All of the above
[ Option A ]
An identifier is the name we give to various program elements like variables, constants, functions, and other user-defined items. However, keywords cannot be used as identifiers because of meaning of each keyword is fixed or already known by the compiler.
Q: 22 Which one of the following is not a keyword for C language?
case
main
default
sizeof
[ Option B ]
The keywords are special words that have a fixed and predefined meaning, decided by the language itself.
| Related to Primitive Data Types | Related to Control Statement | Related to Storage Classes | Related to User-Defined Data Type | Other Purpose |
|---|---|---|---|---|
| int | if | auto | struct | const |
| char | else | static | union | sizeof |
| float | switch | register | enum | volatile |
| double | case | extern | typedef | |
| short | default | |||
| long | break | |||
| signed | continue | |||
| unsigned | goto | |||
| void | do | |||
| while | ||||
| for | ||||
| return |
The main is the name of the function where program execution begins, but it is not reserved by the C compiler as a keyword.
Q: 23 How many tokens are present in the following statement?
int a = b + 5;
5
6
7
4
[ Option C ]
Tokens in int a=b+5; are int, a, =, b, +, 5, and ; So, the total number of tokens is 7.
Q: 24 The backslash constant ‘\b’ can be used for? Choose best answer.
Move cursor back to one position in current line
Move cursor back to one position in current line in destructive nature
Move cursor back to five positions in current line in non-destructive nature
None of these
[ Option A ]
The backslash constant \b (backspace) moves the cursor one position back in the current line. It does not erase or delete the character. It only shifts the cursor position so that the next character printed will overwrite the previous one.
The C language defines several backslash character constants which are used for special purpose. They are called so because each backslash constant starts with backslash (\). These are also called white spaces characters or escape sequence characters.
| ESCAPE SEQUENCE | MEANING |
|---|---|
| \0 | NULL Value. |
| \b | Moves the cursor back one position (non-destructive). |
| \t | Horizontal Tab. |
| \n | Moves the cursor to the first position of the next line. |
| \v | Vertical Tab. |
| \r | Moves cursor to the first position of the current line (non-destructive). |
| \" | To print double Quote. |
| \' | To print single quote. |
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.