C++ Strings
In C++, the one-dimensional array of characters are called strings, which is terminated by a null character \0.
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 above Defined string in C++
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:
Comments
Post a Comment