Yes / No Questions

Question 1 :

Functions cannot return a floating point number

A). Yes
B). No

Explanation :

A function can return floating point value.

Example:

``````#include
float sub(float, float); /* Function prototype */

int main()
{
float a = 4.5, b = 3.2, c;
c = sub(a, b);
printf("c = %f\n", c);
return 0;
}
float sub(float a, float b)
{
return (a - b);
}``````
Output:
c = 1.300000

Question 2 :

Every function must return a value

A). Yes
B). No

Explanation :

No, If a function return type is declared as void it cannot return any value.

Question 3 :

If a function contains two return statements successively, the compiler will generate warnings. Yes/No ?

A). Yes
B). No

Explanation :

Yes. If a function contains two return statements successively, the compiler will generate "Unreachable code" warnings.

Example:

``````#include
int mul(int, int); /* Function prototype */

int main()
{
int a = 4, b = 3, c;
c = mul(a, b);
printf("c = %d\n", c);
return 0;
}
int mul(int a, int b)
{
return (a * b);
return (a - b); /* Warning: Unreachable code */
}``````
Output:
c = 12

Question 4 :

Maximum number of arguments that a function can take is 12

A). Yes
B). No

Explanation :

No, C can accept upto 127 maximum number of arguments in a function.

Question 5 :

Will the following functions work?

``````int f1(int a, int b)
{
return ( f2(20) );
}
int f2(int a)
{
return (a*a);
}``````

A). Yes
B). No

Explanation :

Yes, It will return the value 20*20 = 400

Example:

``````#include
int f1(int, int); /* Function prototype */
int f2(int); /* Function prototype */

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

int f1(int a, int b)
{
return ( f2(20) );
}

int f2(int a)
{
return (a * a);
}``````
Output:
c = 400