The arrays are terminated by a NULL character ('\0')
String constants are formed by text enclosed by double quotes
String variables may be initialized in more than one way. The
following two ways of initializing an array are equivalent: char First_Name[] = {'S', 'a', 'm'};
char First_Name[] = "Sam";
Note: It is incorrect to write char First_Name = "Sam"
You can display a string by specifying its name (without subscripts)
in the cout statement: char First_Name[] = "Sam";
cout << "First Name is: " << First_Name << endl;
To perform string assignments, string handling library functions must
be used. These function prototypes are declared in string.h
Examples of string handling functions:
#include <iostream.h>
#include <string.h>
int main()
{
char name[] = "Sam";
strcpy(name, "Joe"); // copy string to character array
return(0);
}
String functions such as strcpy use the '\0' character to
detect the end of the string
You can copy strings starting at a location other than the
beginning: strcpy(s, "An Advanced Programming Language");
strcpy(t, s);
strcpy(u, s+12);
strcpy(v, u);
strcpy(v+12, "in C++");
More string functions...
// Concatenate string str2 to the end of string str1 strcat(str1, str2);
int length = strlen(str); // Compute the length of string str
/*Compare strings str1 and str2, will return 0 if strings are
identical*/
strcmp(str1, str2);