C++ Strings

A collection of characters written in double quotations is called string or string constant. It may consist of any alphabetic characters, digits and special symbols.

A string is stored as an array of characters.The array is terminated by a special symbol known as null character. it is denoted by the escape sequence \0 and it is used to indicate the end of string.It consists of back slash and 

There are two types of string in C++ Language:


1. C-String


String Declaration
C++ stores as an array of characters. An array is a group of contiguous memory location that can store same type of data.

Syntax
char array_name[length];

Example:
char book[15];

String Initialization

Syntax 
char array_name[length]=value;

Example:

char books[]="CPP LANGUAGE";
or 
char books[] = {'C','P','P',' ','L','A','N','G','U','A','G',' E','\0'};



Example in C++ 

#include <iostream>
using namespace std;
int main() 
{
char books[]="CPP LANGUAGE"; // defining string
cout<<"String = " << books; //output
}

Output:


String with Object 


Example in C++ 

#include <iostream>
using namespace std;
int main() 
{
string books="CPP LANGUAGE"; // defining string
cout<<"String = " << books; //output
}

Output:

<< C++ Arrays        --        C++ Pointers >>