Questions for: Functions
#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);
}
The correct form of function f prototype is float f(int, float);
#include<stdio.h>
int main()
{
printf("%p\n", main());
return 0;
}
In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.
Discuss About this Question.
#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
The function void f() is not visible to the compiler while going through main() function. So we have to declare this prototype void f(); before to main() function. This kind of error will not occur in modern compilers.
Discuss About this Question.
#include<stdio.h>
int f(int a)
{
a > 20? return(10): return(20);
}
int main()
{
int f(int);
int b;
b = f(20);
printf("%d\n", b);
return 0;
}
In a ternary operator, we cannot use the return statement. The ternary operator requires expressions but not code.
Discuss About this Question.
f(int a, int b)
{
int a;
a = 20;
return a;
}
f(int a, int b) The variable a is declared in the function argument statement.
int a; Here again we are declaring the variable a. Hence it shows the error "Redeclaration of a"
Discuss About this Question.
Discuss About this Question.