Functions in C MCQ (Multiple Choise Questions)

 Functions in C MCQ

Functions in C MCQ


1. What is the primary purpose of a function in C?


A. Input

B. Output

C. Encapsulation

D. All of the above


Correct Answer: C. EncapsulationIn C,




2. which keyword is used to declare a function?


A. def

B. function

C. func

D. void


Correct Answer: D. void




3. Which of the following is a valid function name in C?


A. 123_function

B. my_function_2

C. int D. break


Correct Answer: B. my_function_2




4. What is the purpose of a function prototype in C?


A. To declare a variable

B. To define a function

C. To declare the function's signature

D. To assign a value to a variable

Correct Answer: C. To declare the function's signature




5. What is the return type of the main() function in C?


A. int

B. void

C. char

D. float

Correct Answer: int




6. In C, can a function be called before it is defined?


A. No, it's not allowed

B. Yes, as long as it is defined later in the program

C. Yes, anywhere in the program

D. It depends on the compiler

Correct Answer: B. Yes, as long as it is defined later in the program




7. What is the purpose of the "return" statement in a function?


A. To terminate the program

B. To specify the function's input parameters

C. To specify the function's output

D. To return a value to the caller

Correct Answer: D. To return a value to the caller




8. Which of the following functions is called automatically when a program starts?


A. start()

B. run()

C. main()

D. begin()

Correct Answer: C. main()




9. What does a function's "arguments" refer to in C?


A. The data types it returns

B. The values passed to the function when it's called

C. The function's name

D. The number of lines in the function

Correct Answer: B. The values passed to the function when it's called




10. What does the "void" keyword in a function declaration indicate?


A. The function is empty and does nothing

B. The function returns a void pointer

C. The function has no return value

D. The function is not declared properly

Correct Answer: C. The function has no return value




11. What does the "void" keyword in a function declaration indicate?


A. The function is empty and does nothing

B. The function returns a void pointer

C. The function has no return value

D. The function is not declared properly

Correct Answer: C. The function has no return value




12. In C, how can you access the address of a variable?


A. Using the '&' operator

B. Using the '*' operator

C. Using the '@' operator

D. Using the '$' operator

Correct Answer: A. Using the '&' operator




13. What is the purpose of the "static" keyword in a function declaration?


A. It makes the function public

B. It restricts the function to a single file

C. It makes the function a global function

D. It's used to specify the function's return type

Correct Answer: B. It restricts the function to a single file




14. What is function overloading in C?


A. Defining multiple functions with the same name but different parameter lists

B. Calling the same function multiple times

C. Creating a function inside another function

D. Using the same variable name in different functions

Correct Answer: A. Defining multiple functions with the same name but different parameter lists




15. In C, which of the following is a standard library function?


A. print()

B. input()

C. printf()

D. read()

Correct Answer: C. printf()




16. Which of the following is an example of a recursive function in C?


A. for loop

B. while loop

C. main function

D. factorial function

Correct Answer: D. factorial function






17. What is the purpose of the "break" statement in a switch statement within a function?


A. To exit the switch statement

B. To exit the entire function

C. To skip the current iteration of a loop

D. To go to the next case in the switch

Correct Answer: A. To exit the switch statement




18. What is the purpose of the "continue" statement in a loop within a function?


A. To exit the loop

B. To skip the current iteration and continue to the next

C. To restart the loop from the beginning

D. To switch to a different loop

Correct Answer: B. To skip the current iteration and continue to the next




19. Which header file is needed to use functions like malloc() and free() in C?


A. stdio.h

B. conio.h

C. malloc.h

D. stdlib.h

Correct Answer: D. stdlib.h




20. What is a function signature in C?


A. The function's return type and name

B. The function's name and its local variables

C. The function's name and its parameters

D. The function's local variables and parameters

Correct Answer: A. The function's return type and name




21. Which of the following is an example of a standard library function for string manipulation in C?


A. strcopy()

B. stradd()

C. strcat()

D. strconcat()

Correct Answer: C. strcat()




22. What is the purpose of the "exit()" function in C?


A. To close the program

B. To terminate the main function

C. To terminate the current loop

D. To return a value to the caller

Correct Answer: A. To close the program




23. What is the scope of a variable declared within a function in C?


A. Global scope

B. Function scope

C. File scope

D. Block scope

Correct Answer: B. Function scope




24. Which of the following is a type of function in C that doesn't return a value?


A. Value-returning function

B. Non-returning function

C. Void function

D. Recursive function

Correct Answer: C. Void function




25. In C, what is the purpose of the "goto" statement?


A. To create a loop

B. To exit the program

C. To transfer control to a labeled statement

D. To call another function

Correct Answer: C. To transfer control to a labeled statement

Post a Comment

0 Comments