What is the error in the following code? Why is this wrong?

```
int f(int x)
{
int x;
// code for function body
}
```
What will be an ideal response?


The declaration of the variable x in the function body will be flagged by
the compiler as a multiple declaration of the variable Such an attempt at
(re)declaring a parameter violates the C++ rule that all identifiers be declared
exactly once, prior to use. The g++ compiler gives the following (somewhat
cryptic) error messages. (The -fsyntax-only option is to cause checking the
programs syntax, but not generate any other files in the event that there are no
errors. Most compilers have a similar option.)
g++ -fsyntax-only Problem10.cc
Problem10.cc: In function `int f(int)
Problem10.cc:3: declaration of x shadows a parameter
Compilation exited abnormally with code 1 at Mon Jul
10 07:10:07

Computer Science & Information Technology

You might also like to view...

Every node in a binary tree can have pointers to

A) its left and right child. B) its left and right parent. C) binary nodes. D) its end nodes. E) None of the above

Computer Science & Information Technology

Which method can be used to read a whole line from the file?

a. next b. nextLine c. nextInt d. nextDouble

Computer Science & Information Technology

When you make changes to a base style, ________

A) the base style and any styles based on it will all be updated B) only the base style will be updated C) you will be asked to choose whether or not you want styles based on it updated also D) a new style will be created with the change, but the base style itself will not change

Computer Science & Information Technology

Access control mechanisms include access control by authentication servers, access control lists, intrusion detection, physical access control, policy filters, and traffic filters.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology