Yes you can buy hosting from one company and then purchase the domain name from a domain registrar.
That's exactly what I do.
When registering a domain I register domain names through the domain registrar dynadot.com and then host my websites at a different hosting company.
You can have both domain and hosting with the same company but it's best to keep the domain and hosting separate just in case the host goes out of business or causes problems and you need to move your hosting.
Then all you have to do is move your website files to the new host and then change the DNS name servers in your domain registration control panel to point to the new servers.