What is the last entry in an empty array (C ++)?

I put C ++ because I am just starting with C #, and I'm not sure if there is a difference.

if you declare an array

char arr[10] 

and fill in the values ​​for arr [0] via arr [8], what value will be placed in arr [9]?

space ''? The final string is '\ n'? '\ 0'? Or is it nothing at all?

I ask about it because I always used tactics

char word[20];
for(count = 0 ; count < 20 ; count++)
{
  cout << word[count];
}

to print the entire contents of the array, and I was wondering if I could simplify it (for example, if the last entry was "\ 0") using something like this

char word[20];
while(word[count] != '\0')
{
  cout << word[count];
}

this way, I would not need to remember how many pieces of data were entered into the array if all the spaces were not filled.

If you know an even faster way, let me know. I try to make a bunch of errors on arrays.

+3
2

# :

char[] arr = new char[10];

'\0'.

, List<char> , , . StringBuilder. string, .

+5

++ , char word[20], . , #, , , , . , , .

+2
source

Source: https://habr.com/ru/post/1748065/


All Articles