In C++, a one-dimensional array of characters is called strings, terminated by a null character \0. This tutorial describes strings in C++.



Strings Declaration in C++

There are two ways to declare a string in C++:

Example:

Through an array of characters:

char greeting[6];

Through pointers:

char *greeting;

Strings Initialization in C++

Example:

char greeting[6] = {'C', 'l', 'o', 'u', 'd', '\0'};

or

char greeting[] = "Cloud";

Memory representation of the above-defined string in C++:

cplusplus-strings

Example:

#include <iostream>
using namespace std;

int main ()
{
    char greeting[6] = {'C', 'l', 'o', 'u', 'd', '\0'};

    cout << "Tutorials" << greeting << endl;
    system("pause");
    return 0;
}

Program Output:

cplusplus-strings



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram