0

To initialize all values to 0 , we can do

int arr[5] = {0};
arr[1]     = 1  // index 1 is 1 all others contains value of 0

Is it possible to do something like that with dynamicly created array?

int m_size = 5;
int *one = new int[m_size]

especially , when i am reallocating array , using

if( i > m_size ){ // i as index
            int tmp = m_size;
            while( i > tmp){
                tmp*=2;
            }
            double *temp = new double[tmp];
            memcpy(temp,one,m_size);
            m_size = tmp;
            delete[] one;
            one = temp;
Darlyn
  • 4,715
  • 12
  • 40
  • 90

1 Answers1

2

You can achieve what you want this like this (brackets at end):

double *temp = new double[tmp]();

Chris A
  • 1,475
  • 3
  • 18
  • 22