2. S
T
R
I
N
G
S
STRINGS
String is a collection of characters enclosed in between
double quotes.
Example:
“characters”
“Welcome to Strings”
String can also be called as character array. i.e., array of
characters
Every string implicitly terminated with a special character
called NULL ‘0’
According to ASCII table ‘0’ means 0(zero), but ‘0’ means
48.
‘0’ NULL – Byte with all bits as logic zero
3. D
E
C
L
A
R
A
T
I
O
N
As we know that Array is a collection of similar data type
elements. ( int / char / float . . . )
String is a collection of similar type elements called
characters, So String can be declared as array of characters
called character array.
Syntax: <data type> <variable_name>[size];
Example:
char name[10];
Index values: 0 1 2 3 4 5 6 7 8 9
char city[20];
Here size = Number of characters + 1
Compiler automatically supplies Null (‘0’) character to
represent end of the string.
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
4. I
N
I
T
I
A
L
I
Z
A
T
I
O
N
Assigning values to a variable is called initialization
String can be initialized as
char name[6];
name[0] = ‘D’; name[1] = ‘E’; name[2] = ‘N’;
name[3] = ‘N’; name[4] = ‘I’; name[5] = ‘S’;
String can also be initialized at the time of declaration
char name[20]=“DENNIS RITCHIE”;
Or
char name[20]={‘D’,’E’,’N’,’N’,’I’,’S’,‘ ’,’R’,’I’,’T’,’C’,’H’,’I’,’E’}
String can also be initialized without specifying size
char name[ ] = “HAI THIS IS MANOHAR”;
D E N N I S R I T C H I E 0 0 0 0 0 0
H A I T H I S I S M A N O H A R 0
D E N N I S