retagged by
2,189 views
5 votes
5 votes

What error would the following function give on compilation? 

f(int a, int b) 
{ 
int a; 
a=20; 
return a; 
}
  1. Missing parenthesis is $\textit{return}$ statement.
  2. Function should be defined as $\text{int f(int a, int b)}$
  3. Redeclaration of $a$.
  4. None of these.
retagged by

6 Answers

2 votes
2 votes
A) Missing parenthesis in return statement.-> This is wrong because return statement does not require parenthesis.

B) Function should be defined as int f(int a, int b) -> When a function is not defines with any data type in C, it automatically assumes it to return an integer. The same would not be true if the return value would be float or any other data type. So this option is wrong.

C) Redeclaration of variable a. -> This is the correct option because int a is already declared in the argument of the function and inside the function body 'a' is declared once again which will cause error.
1 votes
1 votes
Correct answer is C: Redeclaration of variable "a",which is not allowed and this is the expected error
1 votes
1 votes
The answer would be 'Redeclaration of a' as a is already a parameter here.

'Function should be defined as int f(int a, int b)' won't be a compilation error, it would give unexpected results in the output.
Answer:

Related questions

3 votes
3 votes
3 answers
1
admin asked Mar 31, 2020
1,901 views
What is the correct way to round off $x$, $a$ $\text{float}$ to an $\text{int}$ value?$y=(\text{int})(x+0.5)$$y=\text{int} (x+0.5)$$y=(\text{int}) x+0.5$$y=(\text{int})(\...
4 votes
4 votes
1 answer
2
admin asked Mar 31, 2020
2,133 views
Prior to using a pointer variable it should bedeclared.initialized.both declared and initialized.none of these.
4 votes
4 votes
1 answer
3
admin asked Mar 31, 2020
3,295 views
Output of the following loop isfor(putchar('c');putchar ('a');putchar('r')) putchar('t');a syntax error.cartrt.catrat.catratratratrat...
2 votes
2 votes
1 answer
4
admin asked Mar 31, 2020
1,164 views
If space occupied by two strings $s_1$ and $s_2$ in 'C' are respectively $m$ and $n$, then space occupied by string obtained by concatenating $s_1$ and $s_2$ is alwaysles...