Exercise: Python

Questions for: Functions

Which of the following function declaration is/are incorrect?
A:
int Sum(int a, int b = 2, int c = 3);
B:
int Sum(int a = 5, int b);
C:
int Sum(int a = 0, int b, int c = 3);
D:
Both B and C are incorrect.
Answer: D
No answer description is available. Let's discuss.
Which of the following function / type of function cannot be overloaded?
A:
Member function
B:
Static function
C:
Virtual function
D:
Both B and C
Answer: C
No answer description is available. Let's discuss.
Which of the following statement will be correct if the function has three arguments passed to it?
A:
The trailing argument will be the default argument.
B:
The first argument will be the default argument.
C:
The middle argument will be the default argument.
D:
All the argument will be the default argument.
Answer: A
No answer description is available. Let's discuss.
Which of the following function prototype is perfectly acceptable?
A:
int Function(int Tmp = Show());
B:
float Function(int Tmp = Show(int, float));
C:
Both A and B.
D:
float = Show(int, float) Function(Tmp);
Answer: A
No answer description is available. Let's discuss.
In a function two return statements should never occur.
A:
Yes
B:
No
C:
D:
Answer: B

No, In a function two return statements can occur but not successively.

Example:


#include <stdio.h>
int mul(int, int); /* Function prototype */

int main()
{
    int a = 0, b = 3, c;
    c = mul(a, b);
    printf("c = %d\n", c);
    return 0;
}

/* Two return statements in the mul() function */
int mul(int a, int b)
{
   if(a == 0 || b == 0)
   {
        return 0;
   }
   else
   {
        return (a * b);
   }
}

Output:
c = 0

Ad Slot (Above Pagination)
Quiz