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...

A Windows- based computer is infected with malware and is running too slowly to boot and run a malware scanner. Which of the following is the BEST way to run the malware scanner?

A. Kill all system processes B. Enable the firewall C. Boot from CD/USB D. Disable the network connection

Computer Science & Information Technology

Which of the following can be used to defend against SYN flood attacks?

A) Micro blocks B) SYN cookies C) Stateful packet inspection firewalls D) All of the above

Computer Science & Information Technology