For others to access your website one has to have both. Without a domain name it is not possible for people to access your website.
You need both domain and hosting services to build your website. Web hosting allows access to a server where you can host your websites files for the term you choose which is usually yearly but you can opt for monthly packages as well. Many hosting companies allows discount on buying biennially and triennially and it is always a better option to choose from.
Domain name is also not free to choose and you have to buy the domain name for the term of your choice as well which is also offered in yearly, biennially and triennially terms.
How Domain & Hosting are Related ?
Domain names and webhosting are related in a way that they work together. A domain is the address of a computer (Server) where you website resides in and you can call it a home whereas a domain name is the address to your home in a way.
Do I have to buy them together? Or can I buy them separately?
Domain names and hosting services can be bought from different companies but in that case you have to point you domain name to web hosting company. It is called DNS settings and also name servers. When doing so, it usually takes 24-48 hours to correctly propagate your DNS records.
Therefore it is always advisable to buy a domain and hosting services from the same company especially if you are beginner and don’t want the mess of updating records here and there.