String:
- String is a collection of two or more characters.
- In string we can store alphabets digits and special symbols.
- when we declare array of character type then it is called as string.
- In C, character type array is used to store a string.
Declaration of String:
The declaration of string is similar like Array.
for declaring string we need to specify its size means maximum of how many characters we have to store in string.
Syntax: char string[size];
Example: char str[20];
Here we declare a string variable str of size 20 means variable 'str' characters.
Initialization of String:
while declaring string we can also initialize some value at the time of declaration.
Syntax: char string[size]="text";
Example: char str[20]="programmingsolution";
Here we declare a string variable 'str' of size 20 and assign programmingsolution to it.
Declaration of String:
for declaring string we need to specify its size means maximum of how many characters we have to store in string.
Inputting string:
To input the content in the string two function used as 'scanf()' and 'gets()'.
In 'scanf()' function spaces are not allowed in a string.if we give space then the remaining part will be truncated from string.
In 'gets()' function spaces are allowed in a string.
In 'scanf()' function spaces are not allowed in a string.if we give space then the remaining part will be truncated from string.
In 'gets()' function spaces are allowed in a string.
Syntax: scanf("%s",string_variable);
gets(string_variable);
Example: scanf("%s",str);
gets(str);
0 comments:
Post a Comment