How do you set an empty string...
char string[] = "";
or
char string[50] = "";
or are these both wrong?
Printable View
How do you set an empty string...
char string[] = "";
or
char string[50] = "";
or are these both wrong?
Nothing can be empty it will have some value in it but if I get what you mean
would set all elements to \0, which is as close to empty as you can get.Code:char string[50] = '\0';
They will both work, but perform different purposes.
char CharArray[] = "Something"; // initialize the character string to what's between the "s plus the \0 character at the end.
so
char string[] = ""; // creates an array of one character which would be the \0 character.
char string[50] = ""; // creates an array of 50 characters with the initial string of \0.
You are right either way but it depends on what you want to do as to which one you should use.
A truly "empty" string would be
char *pString = NULL;
cool