The two main functions used are malloc() and free(), which are used to assign and release memory structures for arrays, among other things. You will be treading into difficult waters…
How does the array looks like when it is defined, and no data is in the array? I assume nothing, so no "0".
If the array is an automatic, when it is declared it has whatever junk was in the stack frame that it occupies.
If you "malloc"ed the array, it contains whatever junk was on the heap.
If you "calloc"ed it, it was initialised to zeroes.
If it was "static" or had global scope, then it was initialised to zero before "main" ran.
At no point was it ever "empty" - memory was allocated, and that memory contained something, even if the something was the value zero..
How you manage what defines "empty" is down to you - as has been pointed out, if you're managing a C string, then a simple "myBuffer[0] = '\0';" will suffice.
It may be that setting the index ([u]your[/u] index) into the buffer that you increment when you put in a new character to zero will suffice, since you know when [u]you[/u] have filled the buffer (whatever that means to [u]you[/u]) as far as you want, and want to move on to processing that buffer.
I can't decide if you're trying to make some philosophical point about the relative merits of buffer management in different languages and architectures, or you simply don't understand the nature of the problem you think you face.
I can’t decide if you’re trying to make some philosophical point about the relative merits of buffer management in different languages and architectures, or you simply don’t understand the nature of the problem you think you face.
I just want to know how array’s work and what’s considered as an “Empty” array. Your explanation makes sense and explains everything to me, so thanks a lot.
To filling the array with “0” makes a lot of sens now to me!! And that’s what I’ll do.