# Eltype vs typeof what is the difference?

**URL:** <https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319>\
**Category:** General Usage\
**Tags:** eltype, typeof\
**Created:** [January 31, 2021, 10:31am UTC](https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319 "2021-01-31T10:31:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [January 31, 2021, 10:31am UTC](https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319/1 "2021-01-31T10:31:26Z")

</div>

Hey Julianners,

I want to understand what is the use of eltype.  
Is it always equal with:  
x not iterable: `eltype(x) == typeof(x)`  
x is iterable: `eltype(x) == typeof(x[1])` and some size checking?

Or eltype if specifically for empty iterables?

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [January 31, 2021, 12:09pm UTC](https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319/2 "2021-01-31T12:09:54Z")

</div>

`typeof(x)` give the type of `x`, but, if `x` is a container, `eltype` gives you the type of its contained elements.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [January 31, 2021, 12:11pm UTC](https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319/3 "2021-01-31T12:11:42Z")

</div>

> [@Marcell\_Havlik](#):
>
> x is iterable: `eltype(x) == typeof(x[1])` and some size checking?

Don’t think of the type of the elements of a container this way: it only makes sense if the type of all elements is the same and that type is concrete so it can’t have any subtypes.

---

<div class="post-metadata">

**Author:** ![Marcell\_Havlik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcell_havlik/32/37424_2.png) [@Marcell\_Havlik](https://discourse.julialang.org/u/Marcell_Havlik)\
**Post date:** [January 31, 2021, 12:27pm UTC](https://discourse.julialang.org/t/eltype-vs-typeof-what-is-the-difference/54319/4 "2021-01-31T12:27:48Z")

</div>

Thank you for the answer! I just didn’t understand weather there is something more.
