C Programming - Functions

1.
Which of the following statements are correct about the program?
#include<stdio.h>

int main()
{
    printf("%p\n", main());
    return 0;
}
It prints garbage values infinitely
Runs infinitely without printing anything
Error: main() cannot be called inside printf()
No Error and print nothing
Answer: Option
Explanation:

In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.


2.
There is a error in the below program. Which statement will you add to remove it?
#include<stdio.h>

int main()
{
    int a;
    a = f(10, 3.14);
    printf("%d\n", a);
    return 0;
}
float f(int aa, float bb)
{
    return ((float)aa + bb);
}
Add prototype: float f(aa, bb)
Add prototype: float f(int, float)
Add prototype: float f(float, int)
Add prototype: float f(bb, aa)
Answer: Option
Explanation:

The correct form of function f prototype is float f(int, float);


3.
Which of the following statements are correct about the function?
long fun(int num)
{
    int i;
    long f=1;
    for(i=1; i<=num; i++)
        f = f * i;
    return f;
}
The function calculates the value of 1 raised to power num.
The function calculates the square root of an integer
The function calculates the factorial value of an integer
None of above
Answer: Option
Explanation:

Yes, this function calculates and return the factorial value of an given integer num.