I'm really new to c++ and have just been experimenting around with some code and there's something I don't really seem to get:
#include<iostream>
using namespace std;
int f (const long& i) {
return i+1;
}
void g (long& i) {
f (i);
}
int main () {
long la = 0;
int a = 0;
int b = f (a);
long c = f (7);
la = f (la);
cout << "la = " << la << " a = " << a << endl;
cout << "b = " << b << " c = " << c << endl;
}
So what I don't get: Why does function f accept variables of the type int? a is obviously not a long, but it still accepts it. I don't understand that. Also, since the return type of f is int, does it automatically cast the return result from long to int? I don't really understand what's going on here.