Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Chapter: 9
Q141:
How can you modify a function to handle negative values for an argument in C?
A. Use an if statement inside the function
B. Change the argument type to float
C. Initialize the argument to zero
D. None of the above
Correct Answer: A
Chapter: 9
Q142:
What is the default return type of a function in C if no return type is specified?
A. int
B. void
C. float
D. char
Correct Answer: A
Chapter: 9
Q143:
What does the following function declaration signify: double raiseToPow(double x, int power);?
A. Function to raise x to power
B. Function to calculate power of x
C. Function to return the square of x
D. Function to convert x to power
Correct Answer: A
Chapter: 9
Q144:
What does the void return type signify in a function?
A. Function does not return a value
B. Function always returns void
C. Function returns a double
D. Function returns an integer
Correct Answer: A
Chapter: 9
Q145:
What does the term call by value mean in C?
A. Passing the actual value to the function
B. Passing a reference to the function
C. Passing the address of the variable
D. Passing a copy of the value to the function
Correct Answer: D
Chapter: 9
Q146:
What is the output of square(3) + square(4) if the square function returns the square of a number?
A. 25
B. 49
C. 16
D. 41
Correct Answer: D
Chapter: 9
Q147:
In which scenario would you use the return keyword in a function?
A. To end the function execution and return a value
B. To start a new function
C. To define local variables in a function
D. To continue execution after a function
Correct Answer: A
Chapter: 10
Q148:
What is the primary purpose of using header files in C?
A. To define the main function
B. To include all function prototypes and constants
C. To store local variables
D. To manage dynamic memory
Correct Answer: B
Chapter: 10
Q149:
What directive is used to include a header file in a C program?
A. #include
B. #define
C. #import
D. #use
Correct Answer: A
Chapter: 10
Q150:
What does the #define directive do?
A. Creates a variable
B. Defines a constant or macro
C. Declares a function
D. Includes a library
Correct Answer: B
Chapter: 10
Q151:
How is a global variable different from a local variable in terms of scope?
A. Global variables are only visible within a function
B. Local variables are visible in the entire program
C. Global variables are visible in all functions
D. Local variables are visible in all functions
Correct Answer: C
Chapter: 10
Q152:
void func() { int i; { int i = 10; } } What is the scope of the inner i?
A. Function level
B. Block level
C. Global level
D. Local level
Correct Answer: B
Chapter: 10
Q153:
What does the following code snippet demonstrate?
A. void square(double x) { x = x * x; }
B. Passing by reference
C. Passing by value
D. Memory allocation
Correct Answer: B
Chapter: 10
Q154:
In the Call by Value mechanism, what is passed to the function?
A. The actual value of the variable
B. The address of the variable
C. A copy of the value of the variable
D. The variable’s name
Correct Answer: C
Chapter: 10
Q155:
Why might you use Call by Reference instead of Call by Value?
A. To improve code readability
B. To avoid copying large data
C. To prevent the function from modifying data
D. To pass data in a more compact form
Correct Answer: B
Chapter: 10
Q156:
What is the result of passing the address of a variable to a function?
A. The function creates a copy of the variable
B. The function modifies the original variable
C. The function receives a reference to the variable
D. The function creates a new variable
Correct Answer: C
Chapter: 10
Q157:
Which of the following is NOT a feature of recursion?
A. Elegance of code
B. Memory efficiency
C. A base case that terminates the recursion
D. Potential for stack overflow
Correct Answer: B
Chapter: 10
Q158:
What will be the output of the following recursive function?
A. long fact(long n) { if (n <= 1) return 1; else return n * fact(n-1); }
B. 120
C. 720
D. 1
Correct Answer: B
Chapter: 10
Q159:
In C, which library provides mathematical functions such as square root and logarithms?
A. <math.h>
B. <stdio.h>
C. <stdlib.h>
D. <string.h>
Correct Answer: A
Chapter: 11
Q160:
What is the primary purpose of using arrays in C?
A. To store a collection of data of different types
B. To store a collection of data of the same type
C. To enhance program performance
D. To decrease memory usage
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now