lundi 6 décembre 2021

What values should I fill my arrays with to indicate an empty space?

This is more of an etiquette question than anything else, but when creating new arrays what value, other than zero, should I use to indicate an empty space in the array? For example:

int* arr;
arr = new int[10];

When I create a new array like in the code above, the array will be filled with ten zeroes. The issue I'm having is that I want to use underscores when printing the array to indicate empty spaces, however, I also have zeroes as part of my data set in the array. So, should I just fill the empty array with some arbitrary value that is unlikely to show up in my data set (like -32000 for example), and use that as the indicator for empty space, or is there some sort of null value that I could use instead, so that I can know for a fact that the value at that specific index is definitely an empty space?

Aucun commentaire:

Enregistrer un commentaire