String is a collection of characters. The compiler implicitly which plays the null character (\0) at the end of each string. Hence, Every string ends with a null value. Null is represented as \0. \0 is not a space. \0 is a non printable character.
How to declare string?
Syntax:-
datatype variablename[size];
Ex:- char a[10];
%s is Control string for string
String initialization is not possible. Declaration cum initialization is possible.
How to delcare and initialize a string in a single statement?
Syntax1:-
[size]=“type some string”;
Declaration cum initialization of string and print it.

Note:- If the string is not properly terminated at the time of printing the string we will get some garbage value along with the string.
Syntax2:- datatype variablename[size]={‘character’,’character’,’character’,…};
Write a program read a string and print it.

String initialization is not possible. Declaration, declaration cum initialization is possible.
& is optional while reading a string. Scanf doesn’t consider after space if you type string. To overcome this we use gets function.
gets():- gets() is used to read a string. Scanf statement is used to read any type of data but after the space if you type any string scanf doesnot consider so we use gets() for only strings.
puts():- puts() is used to print a string. Instead of printf statement we use puts(). When you use any gets() or puts() it doesnot allow control strings.
Write a program read a string and print it.

How to declare string?
Syntax:-
datatype variablename[size];
Ex:- char a[10];
%s is Control string for string
String initialization is not possible. Declaration cum initialization is possible.
How to delcare and initialize a string in a single statement?
Syntax1:-
Declaration cum initialization of string and print it.

Note:- If the string is not properly terminated at the time of printing the string we will get some garbage value along with the string.
Syntax2:- datatype variablename[size]={‘character’,’character’,’character’,…};
Write a program read a string and print it.

String initialization is not possible. Declaration, declaration cum initialization is possible.
& is optional while reading a string. Scanf doesn’t consider after space if you type string. To overcome this we use gets function.
gets():- gets() is used to read a string. Scanf statement is used to read any type of data but after the space if you type any string scanf doesnot consider so we use gets() for only strings.
puts():- puts() is used to print a string. Instead of printf statement we use puts(). When you use any gets() or puts() it doesnot allow control strings.
Write a program read a string and print it.

No comments:
Post a Comment