1. strlen() FUNCTION OF string.h
It stops counting where it finds uninitialised character (ie if Arr[i] is uninitialised, it gives length as i)for eg. char S[10];
S[0]='c';
cout<<strlen(S); //This prints '1'
for eg. char S[10];
S[4]='c';
cout<<strlen(S); //This prints '0', even though there is one character
NOTE- Though such case may not be ever encountered in actual use but i just found this out experimenting with the code
Reason- See the function definition of strlen() in string (or string.h on older ones) header file
2. THE NULL CHARACTER
The null character (that terminates strings, ie '\0') has the integer code '0'.(i. cout<<int('\0'); gives 0)
'\n' has code 10
' ' has code 32
txt files terminate with a character with code '-1', but when i tried to print the respective character using cout<<char(-1); it just printed a space!?
//I used Dev C++ Ver 5.11 (compiler)
Comments
Post a Comment
You are free to leave any kind of suggestion, or improvement. It doesn't require you to sign in either.