Edit: The OP (or editor) silently changed some single quotes in the original question to double quotes at some point after providing this answer.
As a result, your code will lead to compiler errors. Your first piece of code:
char buf[10] ; buf = ''
is twice illegal. Firstly, in C there is no such thing as an empty char . You can use double quotes to indicate an empty string, for example:
char* buf = "";
This will give you a pointer to a NUL string, i.e. a single character string containing only the NUL . But you cannot use single quotes without anything inside them - it is undefined. If you need to assign a NUL , you must specify it:
char buf = '\0';
A backslash is needed to disambiguate the character '0' .
char buf = 0;
does the same thing, but the first, in my opinion, is a bit less ambiguous to read.
Secondly, you cannot initialize arrays after they are defined.
char buf[10];
declares and defines an array. The buf array id is now an address in memory, and you cannot change where buf indicates the destination. So,
buf = // anything on RHS
is illegal. For this reason, your second and third code snippets are illegal.
To initialize an array, you must do this during the definition:
char buf [10] = ' ';
will provide you with a 10-digit array with the first char being the space '\040' , and the rest will be NUL , i.e. '\0' . When an array is declared and determined using the initializer, the elements of the array (if any) past those with the given initial values are automatically supplemented with 0 . There will be no “random content”.
If you declare and define an array, but do not initialize it, as in the following:
char buf [10];
You will have random content in all elements.