According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[];
c) main() {int argc; char *argv[]; } d) None of the above
26. What error would the following function give on compilation?
f(int a, int b)
{
int a;
a=20;
return a;
}
a) missing parenthesis in the return statement b) The function should be declared as int f(int a, int b)
c) redeclaration of a d) None of the above
Ans of first question will be a) main(int argc, char *argv[]).and the ans of second will be c) redeclaration of a.
Dharani
May 13th, 2015
a
Kritika SK
Jun 12th, 2015
Answer to the first question::::
The option a is correct.
As we know the syntax of function declaration in C.It is necessary to mention the data type of parameter.otherwise by default the data type will be void and that is not what we want as argc is of integer type and argv is an array and SO option b doesnt follow the syntactical rules of functn declaration and it is incorrect.
Function declaration doesnt contain body of the function which is given in option C. So, option c is also incorrect.
Answer to the second question:::::
option c-redeclaration of a.
one of the parameters of the function is a and the local variable of the function is also a. the value of parameter will be overwritten by value of local variable.
So the error is in redeclaration of a.
According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments? a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[]; c) main() {int argc; char *argv[]; } d) None of the above 26. What error would the following function give on compilation? f(int a, int b) { int a; a=20; return a; } a) missing parenthesis in the return statement b) The function should be declared as int f(int a, int b) c) redeclaration of a d) None of the above
Related Answered Questions
Related Open Questions