D
desktop
I have this code:
void test(int* array)
{
int pp = sizeof(array);
cout << pp << endl;
}
int main(){
int nums[] = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };
int pp = sizeof(nums)/4;
cout << pp << endl;
test(nums);
return 0;
}
In main I can take sizeof(nums)/4 which gives me 12 (correct number of
elements in the array nums).
But when I pass nums to test() and call sizeof again I only get 4.
Why do I get 12 in main and 4 in test()?
void test(int* array)
{
int pp = sizeof(array);
cout << pp << endl;
}
int main(){
int nums[] = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };
int pp = sizeof(nums)/4;
cout << pp << endl;
test(nums);
return 0;
}
In main I can take sizeof(nums)/4 which gives me 12 (correct number of
elements in the array nums).
But when I pass nums to test() and call sizeof again I only get 4.
Why do I get 12 in main and 4 in test()?