Strings in C
A C string is a variable-length array of characters that is delimited by the null character.
A string is a sequence of characters.
A string literal is enclosed in double quotes.
Declaring a String:
A string variable is a valid C variable na
...See more
me and always declared as an array.
The general form of declaration of a string variable is,
char string_name [size];
The size determines the number of characters in the string_name.
When the compiler assigns a character string to a character array, it automatically supplies a null character(‘\0’) at the end of the string.
The size should be equal to the maximum number of characters in the string plus one.
Initializing a String: This can be done in two wa
char c[] = "abcd";
char c[50] = "abcd";
char c[] = {'a', 'b', 'c', 'd', '\0'};
char c[5] = {'a', 'b', 'c', 'd', '\0'};
1. char str1[7]=“Welcome”;
2. char str2[8]={‘W’,’e’,’l’,’c’,’o’,’m’,’e’,’\0’};
A string can be initialized in different ways. We will explain this with the help of an example. Below is an example to declare a string with name as str and initialize it with “GeeksforGeeks”.
Views: 2586
Added: 4 years ago
Answer the Question