What does any element of an array contains, when the array is defined.

I was programming for my MAZE SOLVING ROBO.

and i came across replacing a character, already present, in an array by null value..

what constant shall i use, 0 OR "\n" OR something else ??

another question is that, if i declare an array as : "char a[100] = 0;" What value is currently available in a[1], a[2], a[3]....??

I know this sounds very basic.. but i am really a newbie in coding.

any suggestion would be highly appreciated. :slight_smile:

Thank You.

It depends where the array was declared.
At global scope, it will contain zeroes, but any non-static, local scope array may contain anything.

, if i declare an array as : "char a[100] = 0;"

You can't declare it that way, the compiler will complain.

Thank You.

Then how shall I declare it GLOBALLY? (I mean what would the syntax be?)

I just want to store some values in array(only one character, in upper-case, per element of array). And then delete the undesired values and/or replace them by some other character. So, how to delete those chars and make those array elements "NULL"??

Please please reply. :cold_sweat:

memset or memclr are good starting points

What exactly they do??

Thank You. :slight_smile:

Google is your friend.

if i declare an array as : "char a[100] = 0;" What value is currently available in a[1], a[2], a[3]....??

You'll need braces around the initializer, like this:

char a[100] = { 0 };

If the array has block scope, the first elements will be initialized to the values supplied, and the remaining elements will be initialized to zero, which means, in this case, that the entire array will be initialized to zeros.

However, as AWOL points out, if there is no initialization of an array with block scope, then the array will probably contain whatever garbage happened to occupy that part of memory.

A warning: I don't have a C++ language specification, and the information I've provided comes from the C specification. I'm making the (admittedly dangerous) assumption that the language specifications are in agreement on this.