Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C++ Strings

    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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.