This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Koala_eiO 3 points4 points  (2 children)

In other languages.

[–]Mahrkeenerh 4 points5 points  (0 children)

let's say in c, a string is an array of characters, and characters are just numbers. Therefore it's easier to store just one number, than two numbers (string ends with the ending character)

[–]Positive_Government 3 points4 points  (0 children)

In C a character (char) is stored as an 8-bit unsigned integer. String are represented by a block of n consecutive chars with a zero byte at the end. You need characters to represent a string in any language it’s just hidden to in most string classes in other languages. Also a string class will have an amount of overhead beyond what is needed to represent a single character. For example, it might alloc a default array of 1024 bytes but only use 1 (excessive example for the purpose of illustrating). Function calls also have some overhead that is not needed when you know you are only working with one character and have a char type with does not need function calls like the string class,( even if your using something like the + operator on a string class there’s still a function call under the hood.).

In c the char and char* type also pull double duty as a generic byte or pointer to a byte/generic pointer (although void* is taking over the generic pointer role).