Wednesday 23 November 2016

What is String and operations on string ?


String:

String is a collection of characters. A string is written in double-quotation (“ ”). In C++ string is defined as an array of characters.

Declaration:

char variable_name[length];

Example:
char  chars[20];

In the above example a string variable name is declared of length 20. It means that it can only take 20 character.

Initialization:

char chars[20]= ”qwerty” ;
char chars[]= ”qwerty” ;
char chars[20]= {“q” ,”w”, ”e”, ”r”, ”t”, ”y”} ;
gets() function is used to get string input from user.

Example: 
char name[20];
gets(name);

puts() function is used to print string.
puts(name);

gets() and puts() functions are located in "string.h" library file.

No comments:

Post a Comment