Multiple choice

What error would the following function give on compilation? f(int a, int b) { int a; a=20; return a; }

  1. Missing parentheses in return statement.

  2. The function should be defined as int f(int a, int b).

  3. Redeclaration of 'a'.

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The function has a parameter named 'a', and then inside the function body, 'a' is redeclared as a local variable with 'int a;'. This creates a redeclaration error because you cannot declare a variable with the same name as a parameter in the same scope. Option C correctly identifies this as 'Redeclaration of a'. The parameter 'a' is already declared in the function signature, so declaring it again inside is a compilation error.