what is the difference between
char name='chiheb';
char name="chiheb";
I'm also confused about how char can allow many characters .what is the difference then between string and char;
what is the difference between
char name='chiheb';
char name="chiheb";
I'm also confused about how char can allow many characters .what is the difference then between string and char;
In the first declaration on object of the type char
is initialized by a multi-byte integer character constant the value of which is implementation defined.
For the second declaration the compiler will issue a message that you are trying to convert a pointer to an integer because the string literal used as an initializer is converted to pointer to its first element of the type char *
.
A valid declaration will look like for example
char name = "chiheb"[0]; // or some other used valid index
or
char name = *"chiheb";
or
char *name = "chiheb";