Suppose I have a function
void function(double p[2]) {
cout << p[0] << " " << p[1] << endl;
}
If I try that following code
double a[1] = {1};
double b[2] = {2, 3};
double c[3] = {4, 5, 6};
function(a);
function(b);
function(c);
I get something like
1 2.0778e-317
2 3
4 5
In other words, the 2
seems to get completely ignored and all 3 arrays get passed to the function anyway.
Are the following exactly the same?
void function(double p[2])
void function(double p[])
void function(double *p)
If they are, is there any way to make a function that will only accept an array of a particular length or of at least a particular length? The reason I ask is that the types of a
, b
and c
appear to be different. (You get different results for typeid(a).name()
and typeid(b).name()
for example).