I've created this makeArray function that makes an array in the heap memory via "new" operator, therefore when I return it won't get deleted. I tried testing my code to see that it has successfully created and returned the array by getting its size. The size that it gives me is 2, though I gave it size 10 inside my function. Why is that?
main.cc
Output
2
[Finished in 4.5s]
main.cc
Code:
int* makeArray() {
int* array = new int[10];
return array;
} // end of stringSize
int main( int argc, char** argv ) {
int *array1 = makeArray();
int size = sizeof(array1) / sizeof(array1[0]);
printf("%d\n", size);
} // end of main
Output
2
[Finished in 4.5s]