C Programming - Functions - Discussion

Discussion Forum : Functions - Point Out Errors (Q.No. 1)
1.
Point out the error in the program

f(int a, int b)
{
    int a;
    a = 20;
    return a;
}
Missing parenthesis in return statement
The function should be defined as int f(int a, int b)
Redeclaration of a
None of above
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"

Discussion:
14 comments Page 2 of 2.

Anmol said:   1 decade ago
The default return type of any function is "int", so it is useless to write
"int f(int a, int b)".

Abc said:   1 decade ago
Even return type is also missing rite?

Manishsoni said:   1 decade ago
We can't re-declare any variable in the same block.

Sonia said:   1 decade ago
Can anyone explain me this?


Post your comments here:

Your comments will be displayed after verification.