Explain the error in the following code. You may give the warning message, or error message, your compiler might give for the following error, or you may describe the error. However you present the error, you must explain clearly what is wrong.

```
#include
//Test question
void show_array(int ar[], int size)
{
using namespace std;
for(int i = 0; i < size; i++)
cout << ar[i] << " ";
cout << endl;
}
int main()
{
const int a[6] = {2, 4, 2, 3, 5};
show_array(a, 6);
//...
}
```


```
void show_array(int ar[], int size)
{ //^^^^ should be const to use a as an
//argument.
//. . .
}

show_array(a, 6);//warning: pointer to const given for
//argument 1 of 'void show_array(int*, int)'
```

The error message means that the compiler thinks the argument could be changed by the function, and considers this a violation of the programmer's promise not to change the array when the array was declared const.

Computer Science & Information Technology

You might also like to view...

How long is a sound compared to the original if you increment the sourceIndex by 3 each time through the loop in Program 83?

What will be an ideal response?

Computer Science & Information Technology

The ____ contains some of the most important tools for configuring and customizing Windows.

A. Control Panel B. Windows Explorer C. Start menu D. taskbar

Computer Science & Information Technology

What utility should always be used in order to delete checkpoints?

A. Command prompt B. Windows Explorer C. Hyper-V Manager D. PowerShell

Computer Science & Information Technology

A theme is usually applied to what?

a. An application or Activity b. A Fragment or Activity c. A View or ViewGroup d. A LinearLayout or RelativeLayout

Computer Science & Information Technology