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);
}
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.
Shruthi said:
7 years ago
But Why a & b values are initialised? there is no usage of those.
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.
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.
Manjusha said:
8 years ago
Explain it please.
Anonymous said:
8 years ago
Please explain it.
Priyanka said:
9 years ago
Please explain it.
Sankaran said:
9 years ago
@Ankit.
It assigns the value.
It assigns the value.
Ankit said:
1 decade ago
No, because we don't the value of variable a.
Neha said:
1 decade ago
Can somebody explain it?
Allam said:
1 decade ago
But here how could function f1 know the exist of f2 cause f2 is defined after f1 ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers