FSc · Computer Science (Grade 12)

Unit 6 MCQs

50 solved multiple choice questions with answers.

Q1. A function is

  1. AOnly a class
  2. BOnly a loop
  3. COnly a variable
  4. DA block of code that performs a specific task
Show answer
Answer: D. A block of code that performs a specific task
Report a mistake

Q2. The main advantage of using functions is

  1. AMaking program longer
  2. BIncreasing memory usage only
  3. CRemoving all errors automatically
  4. DCode reusability and modularity
Show answer
Answer: D. Code reusability and modularity
Report a mistake

Q3. A function signature consists of

  1. AOnly return type
  2. BOnly body
  3. CFunction name, return type and parameter list
  4. DOnly function name
Show answer
Answer: C. Function name, return type and parameter list
Report a mistake

Q4. The return type void means

  1. AFunction returns integer
  2. BFunction returns nothing
  3. CFunction returns character
  4. DFunction returns float
Show answer
Answer: B. Function returns nothing
Report a mistake

Q5. Parameters listed in function definition are called

  1. AArguments only
  2. BGlobal variables
  3. CActual parameters
  4. DFormal parameters
Show answer
Answer: D. Formal parameters
Report a mistake

Q6. Values passed to a function when it is called are called

  1. AFormal parameters
  2. BLocal variables only
  3. CGlobal variables
  4. DActual parameters / Arguments
Show answer
Answer: D. Actual parameters / Arguments
Report a mistake

Q7. Local variables are accessible

  1. AOnly within the function in which they are declared
  2. BOnly in header files
  3. CEverywhere in the program
  4. DOnly in main()
Show answer
Answer: A. Only within the function in which they are declared
Report a mistake

Q8. Global variables are accessible

  1. AOnly after main()
  2. BThroughout the program
  3. COnly inside one function
  4. DOnly in main()
Show answer
Answer: B. Throughout the program
Report a mistake

Q9. An inline function is

  1. AAlways stored in memory separately
  2. BNever executed
  3. COnly for classes
  4. DExpanded at the point of call (like macro)
Show answer
Answer: D. Expanded at the point of call (like macro)
Report a mistake

Q10. Function overloading means

  1. AMultiple functions with same name but different parameters
  2. BOnly one function allowed
  3. CChanging return type only
  4. DMultiple functions with same name and same parameters
Show answer
Answer: A. Multiple functions with same name but different parameters
Report a mistake

Q11. Default arguments in a function

  1. AAre compulsory
  2. BCannot be used
  3. COnly work with void functions
  4. DAllow calling function with fewer arguments
Show answer
Answer: D. Allow calling function with fewer arguments
Report a mistake

Q12. The return statement is used to

  1. AStart a loop
  2. BReturn a value from a function and exit it
  3. COnly print a value
  4. DOnly declare a variable
Show answer
Answer: B. Return a value from a function and exit it
Report a mistake

Q13. A function must be

  1. AOnly written in header files
  2. BDeclared or defined before it is called
  3. CAlways defined after main()
  4. DNever declared
Show answer
Answer: B. Declared or defined before it is called
Report a mistake

Q14. Function prototype is also known as

  1. AFunction definition
  2. BFunction declaration
  3. CFunction call
  4. DFunction body
Show answer
Answer: B. Function declaration
Report a mistake

Q15. The body of a function is enclosed in

  1. ACurly braces { }
  2. BAngle brackets < >
  3. CSquare brackets [ ]
  4. DParentheses ( )
Show answer
Answer: A. Curly braces { }
Report a mistake

Q16. Which of the following is a valid function call?

  1. Asum{a, b};
  2. Bsum a, b;
  3. Csum[a, b];
  4. Dsum(a, b);
Show answer
Answer: D. sum(a, b);
Report a mistake

Q17. A function can return

  1. ANo value ever
  2. BUnlimited values
  3. CAt most one value
  4. DMultiple values directly
Show answer
Answer: C. At most one value
Report a mistake

Q18. To return multiple values from a function we can use

  1. AOnly return statement multiple times
  2. BPointers, references or structures
  3. CNot possible
  4. DOnly void
Show answer
Answer: B. Pointers, references or structures
Report a mistake

Q19. Call by value means

  1. ANo value is passed
  2. BOriginal value is always changed
  3. CA copy of the argument is passed
  4. DAddress of argument is passed
Show answer
Answer: C. A copy of the argument is passed
Report a mistake

Q20. Call by reference means

  1. AAddress of the argument is passed
  2. BA copy is passed
  3. COnly constants are passed
  4. DValue cannot be changed
Show answer
Answer: A. Address of the argument is passed
Report a mistake

Q21. In call by value, changes made inside function

  1. ADo not affect the original variables
  2. BAlways affect the original variables
  3. CCause compile error
  4. DAffect only global variables
Show answer
Answer: A. Do not affect the original variables
Report a mistake

Q22. In call by reference, changes made inside function

  1. AAre ignored
  2. BAffect the original variables
  3. CAffect only local copies
  4. DDo not affect original variables
Show answer
Answer: B. Affect the original variables
Report a mistake

Q23. Recursive function is a function that

  1. ACalls itself
  2. BHas no parameters
  3. CNever returns
  4. DCalls another function only
Show answer
Answer: A. Calls itself
Report a mistake

Q24. Every recursive function must have

  1. AA base case (terminating condition)
  2. BNo condition
  3. CInfinite calls
  4. DOnly global variables
Show answer
Answer: A. A base case (terminating condition)
Report a mistake

Q25. Example of recursive function is

  1. ACalculating factorial
  2. BOnly addition of two numbers
  3. COnly printing Hello
  4. DOnly loops
Show answer
Answer: A. Calculating factorial
Report a mistake

Q26. Library functions are

  1. AWritten by the user only
  2. BPre-defined functions available in header files
  3. COnly constructors
  4. DOnly main()
Show answer
Answer: B. Pre-defined functions available in header files
Report a mistake

Q27. User-defined functions are

  1. AOnly main()
  2. BOnly operators
  3. CAlready available in libraries
  4. DWritten by the programmer
Show answer
Answer: D. Written by the programmer
Report a mistake

Q28. The function main() returns

  1. Aint (usually)
  2. Bvoid only
  3. Cchar only
  4. Dfloat only
Show answer
Answer: A. int (usually)
Report a mistake

Q29. A function with no parameters is declared as

  1. Afunction_name();
  2. Breturn_type function_name;
  3. Cfunction_name;
  4. Dreturn_type function_name();
Show answer
Answer: D. return_type function_name();
Report a mistake

Q30. Passing array to a function is actually

  1. ANot possible
  2. BCall by value (entire array is copied)
  3. COnly by return
  4. DCall by reference (base address is passed)
Show answer
Answer: D. Call by reference (base address is passed)
Report a mistake

Q31. The scope of formal parameters is

  1. AEntire program
  2. BLimited to the function body
  3. CGlobal
  4. DLimited to main() only
Show answer
Answer: B. Limited to the function body
Report a mistake

Q32. Function overloading is an example of

  1. ARun-time polymorphism
  2. BEncapsulation
  3. CCompile-time polymorphism
  4. DInheritance
Show answer
Answer: C. Compile-time polymorphism
Report a mistake

Q33. Can we overload functions only by return type?

  1. ANo
  2. BOnly with void
  3. COnly with int
  4. DYes
Show answer
Answer: A. No
Report a mistake

Q34. Default arguments must be

  1. AMiddle parameters only
  2. BNot allowed
  3. CTrailing (rightmost) parameters
  4. DLeading parameters only
Show answer
Answer: C. Trailing (rightmost) parameters
Report a mistake

Q35. Once a default argument is used, remaining arguments

  1. ACause error
  2. BCannot have default values
  3. CMust also have default values
  4. DAre optional always
Show answer
Answer: C. Must also have default values
Report a mistake

Q36. An inline function should be

  1. AVery large
  2. BRecursive only
  3. CSmall and simple
  4. DOnly void
Show answer
Answer: C. Small and simple
Report a mistake

Q37. Advantage of inline function is

  1. ALess memory always
  2. BNo advantage
  3. CMore readable only
  4. DFaster execution (avoids function call overhead)
Show answer
Answer: D. Faster execution (avoids function call overhead)
Report a mistake

Q38. Disadvantage of excessive inlining is

  1. ASpeed always decreases
  2. BCode size may increase
  3. CNo disadvantage
  4. DCode size decreases
Show answer
Answer: B. Code size may increase
Report a mistake

Q39. A function that does not return any value and does not take parameters is declared as

  1. Aint function_name();
  2. Bvoid function_name();
  3. Cfunction_name(void); only
  4. DNone
Show answer
Answer: B. void function_name();
Report a mistake

Q40. The keyword used for call by reference is

  1. A& (ampersand)
  2. B* (asterisk)
  3. C->
  4. D::
Show answer
Answer: A. & (ampersand)
Report a mistake

Q41. Function declaration is also required when

  1. AFunction is defined before main()
  2. BOnly for library functions
  3. CNever required
  4. DFunction is defined after main()
Show answer
Answer: D. Function is defined after main()
Report a mistake

Q42. Nested function (function inside function) is

  1. AAllowed freely
  2. BOnly for main()
  3. CCompulsory
  4. DNot allowed in C++ (standard)
Show answer
Answer: D. Not allowed in C++ (standard)
Report a mistake

Q43. The actual parameters and formal parameters

  1. ANone
  2. BMust have same names
  3. CCan have different names
  4. DMust have same data types only
Show answer
Answer: C. Can have different names
Report a mistake

Q44. Number of actual and formal parameters must

  1. ABe different
  2. BAlways be zero
  3. CMatch (except with default arguments)
  4. DNever match
Show answer
Answer: C. Match (except with default arguments)
Report a mistake

Q45. A function can be called

  1. AAny number of times
  2. BOnly from main()
  3. COnly once
  4. DOnly from other functions
Show answer
Answer: A. Any number of times
Report a mistake

Q46. Stack is used for

  1. AFunction calls and local variables
  2. BOnly arrays
  3. COnly classes
  4. DOnly global variables
Show answer
Answer: A. Function calls and local variables
Report a mistake

Q47. Activation record / Stack frame stores

  1. AOnly code
  2. BLocal variables, return address, parameters
  3. COnly global data
  4. DOnly objects
Show answer
Answer: B. Local variables, return address, parameters
Report a mistake

Q48. When a function finishes execution, control returns to

  1. AOperating system only
  2. BThe beginning of main()
  3. CThe point from where it was called
  4. DThe end of program
Show answer
Answer: C. The point from where it was called
Report a mistake

Q49. Preprocessor directive for mathematical functions is

  1. A#include <vector>
  2. B#include <cmath>
  3. C#include <string>
  4. D#include <iostream>
Show answer
Answer: B. #include <cmath>
Report a mistake

Q50. The overall benefit of functions is

  1. ARemoving need for variables
  2. BBetter organization, reusability and readability of code
  3. CMaking code longer and complex
  4. DEliminating all bugs automatically
Show answer
Answer: B. Better organization, reusability and readability of code
Report a mistake