Second, it depends on where the array is allocated. char Array_[10] = {'a'}; // Initialises the first element to 'a' and the rest to null. C strings (a.k.a. All three are correct, of course; #1 is a straightforward function which does what it says, static objects as in #2 are zero-initialized before anything else, and you can always zero out the entire array by initializing it from {0} (or from {} in C++). ... way to declare and initialize a string. char Array_[10] = {0}; // Initialises all 10 elements to null. You cannot place an array initialize char string. ... basically i have a char * input which is a c char string ... you need to null terminate the strings. if i have and array and have already initialize it as follow Code: unsigned char ... C Programming; clearing array; ... array. A C++ solution might be: *std::find(array, array + 5, '\0') = '\0'; It puts '\0' as array[5] (the sixth element of the array), unless a '\0' already is found among the first five elements, in which case the code is a no-op. 0. download the slides used in this presentation ... // Pre: array must contain a null char marking the end of the data. : Can someone tell me how to safely initialize the following:: : int arr[100]; : : Rgds,: : Rustum: Quick answer: int arr[100] = {0}; Detailed answer: First note that in C, NULL may or may not be the same thing as 0 (zero). Hi Experts, In C, if you want to initialize a char string you would set it to null. #1 and #3 are automatic arrays. char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; If you follow the rule of array initialization then you can write the above statement as follows char greeting[] = "Hello"; Following is the memory presentation of the above defined string in C/C++ Actually, you do not place the null character at the end of a string constant. NULL is for pointers. The C compiler automatically places But arrays of char elements have an additional method to initialize their values: using string literals. When it's the matter of initializing C / C++ Forums on Bytes. If you are used to initializing a char array in C++ like the following: char mask[]={'a', 'b', 'c'}; There is a slight change when doing this in C#: ... home > topics > c / c++ > questions > set char to ... *test = NULL; No. initialize a char array with blank spaces. First of all, only your example #2 deals with a static array. In those days, if you had an array with a thousand structs in it, that was a big array. ... i have to initialize the array of stucture singleIMEIarr to null , ... initializing an array to null. Declare an array of chars without initializing it as in Str1. char How to set an array slot to NULL I ... And what type are the elements of array ? How to set an array slot to NULL I ... And what type are the elements of array ? */ char *myStringPtr = NULL; /* Try to allocate memory on the heap * for an empty string, and save the * pointer to its first byte in * myStringPtr. null-terminated strings) Declaration. The only difference between contents of first array and second string is that second string's got a null character at its end. hi all i have a question. /* * Declare a pointer to char * and initialize it to NULL * It doesn't point to any valid * C string now. A C string is usually declared as an array of char. To define a array of C string with a 2D array, char foo[][4] = {"bar", "baz"}; // why not 3? To zero that array out took noticeable time. char array initialization null character problem I have a char array and i initialize it when i declare it like char chArray[16] = {"abcdefghijklm"};