C Programming - Functions
Exercise : Functions - Point Out Errors
1.
Point out the error in the program
f(int a, int b)
{
int a;
a = 20;
return a;
}
Answer: Option
Explanation:
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"
2.
Point out the error in the program
#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;
}
Answer: Option
Explanation:
In a ternary operator, we cannot use the return statement. The ternary operator requires expressions but not code.
3.
Point out the error in the program
#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
Answer: Option
Explanation:
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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers