Reputation: 335
If I were to access the char *
array inside a string, do the arrays include spaces?
Example.
String s = "1 3";
Would s[1]
be " "
or 3
?
Thank you!
Upvotes: 2
Views: 319
Reputation: 3753
Yes they do.
s[0] == '1';
s[1] == ' '; // equals 32 ascii
s[2] == '3';
It is zero-indexed array with starting element of 0 and ending element of n-1.
Also note that s[1] is not " "
(double quotes) but ' '
(single quotes) because single quotes indicate character literal.
Upvotes: 9
Reputation: 1117
Yes, it includes spaces. s[1]
is ' '
.
Spaces are characters as any other.
Upvotes: 13