Why there is a size difference between calling a parameterized array and calling? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why there is a size difference between calling a parameterized array and calling?

Actually I've seen that, when I try to define an array it's better to allocate the size after defining the index size. So, to define the size that way I wrote this... #include<bits/stdc++.h> using namespace std; main() { int *array,size; cout<<"The size of the array pointer: "<<sizeof(array)<<endl; cout<<"Enter the size of your array: "; cin>>size; array=new int[size]; cout<<"The size of the array pointer: "<<sizeof(array)<<endl; // During the compilation the above line of code is ignored & won't shown in the Console. cout<<"Enter elements:"<<endl; for(int i=0;i<size;i++) { cin>>array[i]; } cout<<"Your array: "; for(int i=0;i<size;i++) { cout<<array[i]<<" "; } cout<<endl<<"The size of the array pointer: "<<sizeof(array)<<endl; } But, from the beginning the size of the array shows 8 Bytes, while each integer takes 4 bytes of memory. I've no problem while storing an array of any size. It works as same as a parameterized array. But, my question is why it took only 8 bytes of memory?

30th Nov 2018, 2:37 PM
Surajit
Surajit - avatar
1 Answer
+ 5
https://stackoverflow.com/questions/492384/how-to-find-the-sizeof-a-pointer-pointing-to-an-array 8 bytes is of that address of that pointer and not the total memory pointed by that pointer
30th Nov 2018, 2:50 PM
Rstar
Rstar - avatar