+ 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?
3 Réponses
+ 8
That is actually the size of the pointer.
+ 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.
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;
}
}