what is the default value of an array in C++?

前端 未结 5 1381
情歌与酒
情歌与酒 2021-01-06 09:12

If I were to create an array with int* array = new int[10]; and fill part of the array with values, how can I check how much of the array is filled? I want to l

5条回答
  •  -上瘾入骨i
    2021-01-06 09:34

    This is how to set a default value in C++ when making an array.

    int array[100] = {0};
    

    Now every element is set to 0. Without doing this every element it garbage and will be undefined behavior if used.

    Not all languages are like this. Java has default values when declaring a data structure but C++ does not.

提交回复
热议问题