+ 1

What's the problem occurs during allocating an Array dynamically?

Actually I'm trying to define an Array dynamically by using "new". So, here is the syntax... int *array,size; cin>>size; array=new int[size]; During this memory allocation I found that, the array only takes 8 bytes of memory no matter how big I want that Array to be. Please, tell me where I'm wrong?

29th Nov 2018, 12:17 PM
Surajit
Surajit - avatar
3 odpowiedzi
+ 8
That is actually the size of the pointer.
29th Nov 2018, 2:11 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
How do you determine that? If you only do sizeof(array) you will just get the size of the pointer. sizeof(array[1]) for example is 4 bytes, like it should be.
29th Nov 2018, 12:40 PM
Matthias
Matthias - avatar
0
#include<bits/stdc++.h> using namespace std; template<class money> money requiredNotes(money withdraw) { int availableNotes[6]={1,2,5,10,50,100}; int count=0; for(int i=0;i<6;i++) { count=count+(withdraw/availableNotes[i]); withdraw=(withdraw%availableNotes[i]); } return count; } main() { int Test,*Result,withdraw; cin>>Test; Result=new int[Test]; for(int i=0;i<Test;i++) { cin>>withdraw; Result[i]=requiredNotes(withdraw); } for(int i=0;i<Test;i++) { cout<<Result[i]<<endl; } }
29th Nov 2018, 9:30 PM
Surajit
Surajit - avatar