C++ Strings

An array of characters in C++ is called a string. The null character also has a role in C++. A string is terminated by a null character, i.e., \0. In this lesson, we will learn how to work with strings in C++.

Let’s first see what we meant by strings. The following is a string,

We will now learn how to declare and initialize the above string in C++:

We haven’t added the null character above, since the compiler adds it on its own. In addition, we haven’t added size, since it is optional. Let’s see the entire example.

Let’s see an example to create a string in C++:

Here is the output:

You can also declare and initialize the above string like the following, with extra space for the null character and size in square brackets:

Above, we added an extra size for the array to hold a null character.

Now let’s see another example of a string,

The declaration and initialization of the above string,

Strings in C++

 

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

C++ Tokens
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading