In C++, to initialize all 1D-array elements as zeroes:
int array[5] = {0}; //Set all elements to zeroes.
To initialize every element of an int 2D-array to zeroes, we can do this:
int matrix[5][5] = {0}; //Set all elements to zeroes.
So if I am not using functions like memset
and just populating the 2D-array of char
with "empty values". I probably can do this:
char matrix[ROWS][COLS] = {'\0'}; //Set all elements to '\0'
So my question is:
Can I safely assume it is the same as writing it as char matrix[ROWS][COLS] = {0};
since the ASCII value of '\0'
is 0
?
I have tested the output, initializing it as \0
and 0
seems to be the same. But will it always work the same way in different OS or different compilers?
Some pages I have already visited:
What is the difference between NULL, '\0' and 0
The difference between 0 and '0' in array
PS: I am not asking difference of 0 and '0'. I am asking about 0 and '\0'.