A string is used to store a word or a sentence. This string concept can be obtained through an array of characters. The last character of a string should be a null character. Null character is '10'. String has no separate data type.
We should always enclose the string in double quotes.
String declaration
A string variable can be declared using a character array.
Syntax:
char variable name[size];
EX:
char name[20];
Here name is a string variable. Up to 20 characters can be given inside this name variable.
Initializing String
char program [4]="java"; \\ If you give it like this, an error will appear.
char program [5]="java"; This is the correct method.
Four characters can be stored in the variable called program[4].
There are four characters in java. So, the word java can be stored in a string variable called program[4].
But there is one thing to note here. string always has no place to store null character.
A memory is required to store the null character, so program[4]="java"; It is wrong to give that. The correct method is to give program[5]="java".
Way 2:
char program[]="java";
So the compiler takes the memory size of 4 characters and null character in the variable called program[] in the word java.
Here, the variable called program[] is not given size. Can also be given through character.