By: aathishankaran Emailed: 1768 times Printed: 2515 times
Arrays are not confined to numeric elements only. They also can consist of characters. A string is stored as an array of characters.
To assign values to character array, the following is written:
Char_array = ‘B’;
Char_array = ‘I’;
Char_array = ‘N’;
Char_array = ‘G’;
Char_array = ‘O’;
It can also be done as:
Char_array = “BINGO”;
Since a string can be of any length, the end of the string is marked with the character ‘\0’, known as a string terminator
B I N G O \0
Subscripts-> 0 1 2 3 4 5
A string terminator is automatically appended when a character array is initialized with asset of characters (Char_array = “BINGO”} and whenever a string is accepted using the keyword accept.
While declaring a character array, the array must be large enough to hold the longest string that is to be read, plus one extra element to hold the string terminator.
Initializing Character Arrays
char City = “CALIFORNIA”;
Example : Finding the length of a character array.
display “Please Enter a String:”;
Length = 0;
While ( String [Length] !=’\0’)
display ”Length of the String is”;
Scanning character by character in an array is also termed as traversing.
Be the first one to add a comment
Most Viewed Articles (in Java )
Most Emailed Articles (in Java)