Actually both are same. hosts file is the default inventory file with this default name in ansible after it's installation. We can have multiple inventory files (with any name, can also be a .ini file) and refer to the adhoc commands with -i attribute. We just have to follow the syntax for declaring groups or host names. hosts/inventory file can be in any path in the system where ever ansible command works.