Function(C Program ) Questions and Answers

Question 1. Use of functions
  1.    Helps to avoid repeating a set of statements many times.
  2.    Enhances the logical clarity of the program.
  3.    Helps to avoid repeated programming across programs.
  4.    Makes the debugging task easier.
  5.    All of the above
Explanation:-
Answer: Option E. -> All of the above

Question 2. Any C program
  1.    Must contain at least one function.
  2.    Need not contain any function.
  3.    Needs input data.
  4.    None of the above
Explanation:-
Answer: Option A. -> Must contain at least one function.
At least one function which must be included in any C program is main().

Question 3. What will happen after compiling and running following code?
main()
{
printf("%p", main);
}
  1.    Error
  2.    Will make an infinite loop.
  3.    Some address will be printed.
  4.    None of these.
Explanation:-
Answer: Option C. -> Some address will be printed.
Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They will be printed as hexadecimal numbers.

Question 4. What is function?
  1.    Function is a block of statements that perform some specific task.
  2.    Function is the fundamental modular unit. A function is usually designed to perform a specific task.
  3.    Function is a block of code that performs a specific task. It has a name and it is reusable.
  4.    All of the above
Explanation:-
Answer: Option D. -> All of the above

Question 5. Determine output:
main()
{
int i = abc(10);
printf("%d", --i);
}
int abc(int i)
{
return(i++);
}
  1.    10
  2.    9
  3.    11
  4.    None of these.
Explanation:-
Answer: Option B. -> 9
return(i++) it will first return i and then increment. i.e. 10 will be returned.

Question 6. Which of the following is a complete function?
  1.    int funct();
  2.    int funct(int x) { return x=x+1; }
  3.    void funct(int) { printf(“Hello"); }
  4.    void funct(x) { printf(“Hello"); }
  5.    None of these
Explanation:-
Answer: Option B. -> int funct(int x) { return x=x+1; }

Question 7. What will be printed when this program is executed?
int f(int x)
{
if(x
  1.    4 5 6 7
  2.    1 2 3 4
  3.    4
  4.    Syntax error
  5.    Runtime error
Explanation:-
Answer: Option C. -> 4
In this recursive function call the function will return to main caller when the value of x is 4. Hence the output.

Question 8. The function scanf() returns .........
  1.    The actual values read for each argument.
  2.    1
  3.    0
  4.    The number of successful read input values.
  5.    ASCII value of the input read.
Explanation:-
Answer: Option D. -> The number of successful read input values.
According to the prototype, the return type of scanf( ) function is int, that is the number of successful read input values.

Question 9. Functions have ..........
  1.    Local scope
  2.    Block scope
  3.    File scope
  4.    Function scope
  5.    No scope at all
Explanation:-
Answer: Option C. -> File scope

Question 10. The recursive functions are executed in a ...........
  1.    Parallel order
  2.    First In First Out order
  3.    Last In First Out order
  4.    Iterative order
  5.    Random order
Explanation:-
Answer: Option C. -> Last In First Out order
Because for each function call an entry is created in stack frame( known as Active Record Instance), and are executed in LIFO manner.