What is difference between "a" and 'a'?

What does function sizeof() do?


julia> length('a')

julia> sizeof('a')

julia> sizeof("βˆ€")

julia> sizeof('βˆ€')

julia> sizeof("🍎")

And if sizeof() gives us the size of used memory in bytes why there is difference between β€œa” and β€˜a’ ?

"a" is a String whereas 'a' is a Char:

julia> typeof("a")

julia> typeof('a')

Hence there representation in memory is different.

1 Like

I’m not a string/char expert so I can’t tell you much about the actual sizes of these objects, I’m afraid. However, you might want to take a look at Base.summarysize:

julia> Base.summarysize("a")
julia> Base.summarysize('a')
1 Like

See the help, eg ?sizeof.

This is extensively documented, please read this chapter:


Are you sure that there is an explanation why computer needs 1 byte to store String "a" while to store char 'a' it needs 4 byte?

A Char value represents a single character: it is just a 32-bit primitive type with a special literal representation and appropriate arithmetic behaviors, and which can be converted to a numeric value representing a Unicode code point.


Whether these Unicode characters are displayed as escapes or shown as special characters depends on your terminal’s locale settings and its support for Unicode. String literals are encoded using the UTF-8 encoding. UTF-8 is a variable-width encoding, meaning that not all characters are encoded in the same number of bytes (β€œcode units”). In UTF-8, ASCII characters β€” i.e. those with code points less than 0x80 (128) – are encoded as they are in ASCII, using a single byte, while code points 0x80 and above are encoded using multiple bytes β€” up to four per character.

Its all there


Yes. Please just read it, and feel free to ask here if something is unclear.

Also note that sizeof("a") does not tell how how much memory the computer uses (since it does not contain the information for length, just the contents).

You are possibly looking for Base.summarysize("a"), which is 8 bytes for the length (Int) plus the byte 0x61 for the character β€˜a’ (Strings are stored in UTF-8, which is variable-width).

1 Like