What is Cstring in C++?
Strings are commonly used in the C++ programming language. Examples include Dog, Cat, paper, etc.
CStrings
CStrings are similar to normal strings, but they contain an extra null character at the end of the string that makes them Cstrings. This null character corresponds to the end of the string.
Code
#include <iostream>using namespace std;int main() {// All string are an array of characters.// Let's to make a Cstring array of characters.char string1[4] = {'U','S','A','\0'};cout << string1 << endl;// There is another way we can initialise it.char string2[10] = "Educative";cout << string2 << endl;char string3[]="";cout << string3 << endl;return 0;}
In the code above, we made three strings, string1, string2, and string3.
- For
string1, the array length is4even though there are3letters inUSA. The last character refers to the Null character\0, "which demonstrates the end of the string. string2is initialized in a different manner.string3only represents a NULL character which is empty.
If you skip the null character, it may result in an exception or inaccurate outputs.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved