I want to pass value of array in function by reference
My first try with variable (it works well):
#include <iostream> using namespace std; int input(int &); int main() { int a; input(a); cout << "the value : " << a << endl; system("pause"); return 0; } int input(int &a) { cin >> a; }
But when i change
a
toa[]
like in the following code, it doesn't work#include <iostream.h> using namespace std; int input(int &[]); int main() { int a[2], i; input(a); for(i=0;i<=2;i++) { cout << a << endl; } system("pause"); return 0; } int input(int &a[]) { int i; for(i=0;i<=2;i++) { cin >> a[i]; } }