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

**URL:** <https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546>\
**Category:** New to Julia\
**Tags:** question, strings\
**Created:** [October 6, 2019, 8:25am UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546 "2019-10-06T08:25:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dito/32/10039_2.png) [@Dito](https://discourse.julialang.org/u/Dito)\
**Post date:** [October 6, 2019, 8:25am UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/1 "2019-10-06T08:25:31Z")

</div>

What does function `sizeof()` do?

```julia
sizeof("a")
1

julia> length('a')
1

julia> sizeof('a')
4

julia> sizeof("∀")
3

julia> sizeof('∀')
4

julia> sizeof("🍎")
4

```

And if `sizeof()` gives us the size of used memory in bytes why there is difference between “a” and ‘a’ ?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [October 6, 2019, 8:39am UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/2 "2019-10-06T08:39:49Z")

</div>

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

```julia
julia> typeof("a")
String

julia> typeof('a')
Char

```

Hence there representation in memory is different.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [October 6, 2019, 8:42am UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/3 "2019-10-06T08:42:28Z")

</div>

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
julia> Base.summarysize("a")
9                           
                            
julia> Base.summarysize('a')
4                           

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 6, 2019, 9:34am UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/4 "2019-10-06T09:34:07Z")

</div>

> [@Dito](#):
>
> What does function `sizeof()` do?

See the help, eg `?sizeof`.

> [@Dito](#):
>
> why there is difference between “a” and ‘a’ ?

This is extensively documented, please read this chapter:

[https://docs.julialang.org/en/v1/manual/strings/](https://docs.julialang.org/en/v1/manual/strings/)

---

<div class="post-metadata">

**Author:** ![Dito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dito/32/10039_2.png) [@Dito](https://discourse.julialang.org/u/Dito)\
**Post date:** [October 6, 2019, 12:40pm UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/5 "2019-10-06T12:40:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 6, 2019, 12:48pm UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/6 "2019-10-06T12:48:39Z")

</div>

> 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](https://en.wikipedia.org/wiki/Code_point).

and

> 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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 6, 2019, 12:52pm UTC](https://discourse.julialang.org/t/what-is-difference-between-a-and-a/29546/7 "2019-10-06T12:52:40Z")

</div>

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](https://en.wikipedia.org/wiki/UTF-8), which is variable-width).
