A string is a one-dimensional array of characters that ends with the null character '0.'
A null-terminated string, on the other hand, consists of the string's characters followed by a null.
The declaration and initialization that follow generate a string that contains the word "Hello."
To accommodate the null character at the end of the word "Hello," the character array containing the string must be one bigger than the number of characters in the word.
char greeting[6] = 'H', 'e', 'l', 'l', 'o', '0'; char greeting[6] = 'H', 'e', 'l', 'l', 'o', '0'; char greeting[6] = 'H',
This null character denotes the string's end.
Double quotations are usually used to surround strings.
Characters in C are surrounded by single quotations
char string[20] = {‘f’, ’r’, ‘e’, ‘s’, ‘h’, ‘2’, ‘r’, ‘e’, ‘f’, ’r’, ‘e’, ‘s’, ‘h’, ‘\0’};
char string[20] = “fresh2refresh”;
char string [] = “fresh2refresh”;
|