Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 22
Q381:
Which of the following is correct about function calling by reference?
A. The actual value is passed to the function
B. The function receives a copy of the value
C. The function receives the address of the value
D. The function receives a new variable
Correct Answer:
C
Chapter: 22
Q382:
What is the primary use of pointers in C/C++?
A. To store the memory address of a variable
B. To store large numbers
C. To perform arithmetic operations
D. To access static variables
Correct Answer:
A
Chapter: 22
Q383:
In C/C++, what will be the result of the expression a = b inside an if statement?
A. The code block will always execute
B. The assignment will fail
C. The if condition will always be false
D. The if condition will always be true
Correct Answer:
A
Chapter: 22
Q384:
What is the role of the else block in an if-else statement?
A. It is executed if the condition in the if statement is true
B. It is executed if the condition in the if statement is false
C. It is executed if the condition in the if statement is true or false
D. It is optional and can be omitted
Correct Answer:
B
Chapter: 22
Q385:
How are multi-dimensional arrays stored in C/C++?
A. In row-major order
B. In column-major order
C. In random order
D. In any specified order
Correct Answer:
A
Chapter: 22
Q386:
What does the tellg function do in file handling?
A. It moves the file pointer
B. It provides the current position in the file
C. It opens a file
D. It writes to the file
Correct Answer:
B
Chapter: 22
Q387:
Which loop construct ensures that the loop body is executed at least once?
A. while loop
B. for loop
C. do-while loop
D. foreach loop
Correct Answer:
C
Chapter: 23
Q388:
What does the preprocessor in C do before compilation?
A. Optimizes the code
B. Enhances the code
C. Replaces functions
D. Creates a new source code file
Correct Answer:
B
Chapter: 23
Q389:
What is the purpose of the #include directive in C?
A. To add comments to the code
B. To include header files
C. To define constants
D. To replace variables
Correct Answer:
B
Chapter: 23
Q390:
How does the preprocessor treat the file included using #include<somefile>?
A. Replaces it with the content of the file
B. Optimizes it
C. Compiles it separately
D. Ignores it
Correct Answer:
A
Chapter: 23
Q391:
Where does the compiler search for a file included using #include<somefile>?
A. Current working directory
B. User's home directory
C. Specific include directory
D. Temporary folder
Correct Answer:
C
Chapter: 23
Q392:
What file extension is usually used for header files in C?
A. .c
B. .h
C. .cpp
D. .exe
Correct Answer:
B
Chapter: 23
Q393:
What is the difference between using angle brackets and quotation marks with #include?
A. Angle brackets search current directory
B. Quotation marks search specific folder
C. Angle brackets search specific directory
D. Quotation marks search parent directory
Correct Answer:
C
Chapter: 23
Q394:
What is a macro in C?
A. A special type of variable
B. A constant
C. A function
D. A symbolic name replaced by its definition
Correct Answer:
D
Chapter: 23
Q395:
Which directive is used to define a macro in C?
A. #define
B. #include
C. #undef
D. #ifdef
Correct Answer:
A
Chapter: 23
Q396:
What happens when a macro is used in the code?
A. It is executed like a function
B. It is replaced by its definition
C. It generates an error
D. It is ignored
Correct Answer:
B
Chapter: 23
Q397:
Why should parentheses be used in parameterized macros?
A. To ensure correct calculation precedence
B. To make it look neat
C. To avoid syntax errors
D. To allow function calls
Correct Answer:
A
Chapter: 23
Q398:
What is conditional compilation in C?
A. Compiling code based on conditions
B. Compiling code selectively based on macros
C. Skipping errors in compilation
D. Running the code conditionally
Correct Answer:
B
Chapter: 23
Q399:
Which directive checks if a symbol is defined before executing a block of code?
A. #define
B. #include
C. #ifdef
D. #endif
Correct Answer:
C
Chapter: 23
Q400:
Which directive is used to undefine a previously defined macro?
A. #undef
B. #ifndef
C. #ifdef
D. #else
Correct Answer:
A