why this code shows error while compiling?
#include <iostream>
using namespace std;
void foo(int& x){
// cout<<x;
}
int main(){
//int x=3;
foo(3);
return 0;
}
but by changing the argument to const it compiles properly
#include <iostream>
using namespace std;
void foo(const int& x){
// cout<<x;
}
int main(){
//int x=3;
foo(3);
return 0;
}
but i am still passing an integer so how does it compiles by adding const in the argument?