
Strings 367
Write a program to initialize a string using different formats.
# include <iostream.h>
# include <constream.h>
# include <string.h>
int main()
{
clrscr();
char text[]=”Welcome”; // Using double quote
char text1[]={‘W’,’e’,’l’,’c’,’o’,’m’,’e’,’\0’}; // using single
quote
cout<<“\n First string : “<<text;
cout <<“\n Second string : “<<text1;
return 0;
}
OUTPUT
First string : Welcome
Second string : Welcome
Explanation
In this program, two methods of initialization of arrays are used. Here, both declaration and
initialization are done in the same statement.
char text[]=”Welcome”;
In this statement array text[ ] is declared and it is initialized with ...