G
Guest
Hi, folks,
As the Subject suggests, array variable will retrogress as the
parameter of the function actually taking pointer as its argument,
like this:
int f(int* i) {
cout << sizeof(i) << endl;
return 0;
}
main() {
int a[100];
int *p = new int(1);
f(a);
f(i);
}
The output will be:
4
4
It's intuitive and straightforward, let's think another problem:
typedef int IntArray[100];
int g(IntArray& ia) {
cout << sizeof(ia) << endl;
}
main() {
IntArray ia;
g(ia);
}
The output is:
400
Can anybody explain what's going on here, a lot of thanks will go to
you.
As the Subject suggests, array variable will retrogress as the
parameter of the function actually taking pointer as its argument,
like this:
int f(int* i) {
cout << sizeof(i) << endl;
return 0;
}
main() {
int a[100];
int *p = new int(1);
f(a);
f(i);
}
The output will be:
4
4
It's intuitive and straightforward, let's think another problem:
typedef int IntArray[100];
int g(IntArray& ia) {
cout << sizeof(ia) << endl;
}
main() {
IntArray ia;
g(ia);
}
The output is:
400
Can anybody explain what's going on here, a lot of thanks will go to
you.