PDA

View Full Version : i got the conecpt of string array as i asked before but i did not get this point



sana.pari
04-24-2011, 04:52 PM
Dear Sir,

i got the conecpt of string array as i asked before but i did not get this point then why just one character like 'a' is taking two byts. what is null character? and if 'a' is taking 2 bytes then we should declare like char s1[2] but we are doing just char s1. so please explain more please.



Thank you very much

Support
04-24-2011, 04:52 PM
Dear student!
Null character is special character that is added to array just to indicate end of string. If a string has n characters then it requires an n+1 element array (at least) to store it.
A string variable s1 could be declared as follows:
char s1[10];
The string variable s1 could hold strings of length up to nine characters since space is needed for the final null character.
The single-character string "a" is stored in two consecutive bytes holding the character `a' and the null character. It would declared as follow:
char s1[2];