Блог пользователя Frankenstein123

Автор Frankenstein123, 6 лет назад, По-английски

So after having searched at a number of places online, I have not yet completely understood how the different methods to fill a particular value at every place in a block of memory in C++. For the sake of clarity, I wish to know how the following methods differ.

1)

int arr[100] = {0};

2)

int arr[100];
int main(){
    fill(arr, arr+100, 0);
}

3)

int arr[100];
int main(){
    memset(arr, 0, sizeof(arr));
}

Please describe the difference in the time complexity and performance of these operations and also what happens when they are used for a higher dimension array, like for declarations of the type int arr[100][100][100];.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится