I am newbie in c++ and just learning it. I have written the following code.
#include<iostream>
#include<cstdio>
using namespace std;
void first(int &x,int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<x+i;
}
cout<<endl;
}
void second(int *x,int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<*x+i;
}
cout<<endl;
}
int main()
{
int exm[5]={1,2,3,4,5};
first(exm[0],5);
second(exm,5);
return 0;
}
this program gives output correctly.but the problem is i don't understand the differences between using & and * in function parameters... both are the techniques of passing arguments by references and when we pass by reference we just send the memory address... but in function first when i tried to call the function as follows
first(exm,5);
function occurred an error. why ? but when i called the function as follows
first(exm[0],5);
it compiled properly and gave right output...but i know that the both calling is equivalent...
then why this error occured?
what is the difference between using & and * in function parameters?