C Programming - Functions - Discussion

Discussion Forum : Functions - Yes / No Questions (Q.No. 5)
5.
Will the following functions work?
int f1(int a, int b)
{
    return ( f2(20) );
}
int f2(int a)
{
    return (a*a);
}
Yes
No
Answer: Option
Explanation:

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

Example:


#include <stdio.h>
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

Discussion:
10 comments Page 1 of 1.

Allam said:   1 decade ago
But here how could function f1 know the exist of f2 cause f2 is defined after f1 ?

Neha said:   1 decade ago
Can somebody explain it?

Ankit said:   1 decade ago
No, because we don't the value of variable a.

Sankaran said:   9 years ago
@Ankit.

It assigns the value.

Priyanka said:   9 years ago
Please explain it.

Anonymous said:   8 years ago
Please explain it.

Manjusha said:   8 years ago
Explain it please.

Al_nazre said:   8 years ago
A function cannot be defined inside another function but can called inside another function. This is what happens here.

Amit kumar said:   7 years ago
Intially f1 function accept the value of variable a and b, again function f2 pas a value of a=20;again f2 function aperation a*a=20*20=400.

Shruthi said:   7 years ago
But Why a & b values are initialised? there is no usage of those.

Post your comments here:

Your comments will be displayed after verification.