I have the following code:
Code:
#include <iostream>
using namespace std;
void change(int in1[]);
int main()
{
int a[5]={1, 1, 1, 1, 1}, c;
for(c=0; c<5; c++)
cout<<a[c]<<endl;
change(a);
for(c=0; c<5; c++)
cout<<a[c]<<endl;
}
void change(int in1[])
{
int count;
for(count=0; count<5; count++)
in1[count]*=2;
}
This code outputs the following:
Code:
1
1
1
1
1
2
2
2
2
2
I also have this code which is similar:
Code:
#include <iostream>
using namespace std;
void change(int& in1);
int main()
{
int a=1;
cout<<a<<endl;
change(a);
cout<<a<<endl;
}
void change(int& in1)
{
in1*=2;
}
It outputs the following:
Why does the second code require an ampersand and the first one not?