Code:#include <iostream.h> #include <stdlib.h> #include <time.h> void printArray(int array[]) { cout<<"size of array: "<<sizeof(array)<<endl; for (int i=0;i<sizeof(array);i++) cout<<array[i]<<" "; cout<<endl; } int main () { int array[10]; srand ( time(NULL) ); for (int i=0;i<sizeof(array);i++) array[i] = rand() % 100; cout<<"size of array: "<<sizeof(array)<<endl; printArray(array); return 0; }
prints:
size of array: 40
size of array: 4
7 89 51 6 (or some other random numbers, key thing is that there are only 4 displayed)
why is the array differnt sizes for the function and main body?
also what is a mathematical way of using sizeof() to get the length of the array (I want to get 10 from it).