• Register
100 points
7 4

Strings are easy to handle and manage. Strings are the sequence of characters and we can see them as an array of characters. Computer ends the string with a special character called null character. In other words the end of the string is decided with the null character.

In C++ what represents the null character?
In C++ the literal value of null character is represented as ‘\0’.

Let's take an example, assume we have an array of length 20 i.e., we can store up to 20 elements in this array. If you store a five character long word in this array, then the compiler puts the null character at the end of the last character.


Strings and null-terminated character sequences

In C strings are represented by the typical type of plain arrays with null-terminated sequences. In C++, the standard library defines a specific type of string, but still, plain arrays with null-terminated sequences of characters is a way of representing strings known as C-strings.
For example, both input and output keywords of C++ support C-strings directly, by allowing them to be directly extracted and inserted from cin and cout respectively like strings.

#include <iostream>
#include <string>
using namespace std;

int main ()
  char question1[] = "What is your name? ";
  string question2 = "Where do you live? ";
  char answer1 [80];
  string answer2;
  cout << question1;
  cin >> answer1;
  cout << question2;
  cin >> answer2;
  cout << "Hello, " << answer1;
  cout << " from " << answer2 << "!\n";
  return 0;


What is your name? Homer
Where do you live? Greece
Hello, Homer from Greece!
100 points
7 4