Usually two or more network devices (pc, laptop, mobile, printers, etc) connect to a network layer. This is done either wired or wireless. For wireless connection for example you need a wireless access points. For wired connections we usually use a switch port (this is cable multiplex in common words). Now, a typical ethernet switch does not give any ip address.
In most cases (for simple use) in home we use a device that provides access to Internet (this is called router OR modem). Those devices (mostly routers) include also some minimal ethernet switch (some 4-5 ports at back for ethernet connectivity). On those ports we connect our devices (better not use the last port, start from port-1).
For simplicity those devices offer a service called DHCP. This is a service runs in the device and every time a new computer/laptop/printer etc connects to the router (wired or wireless) then if that computer asks for an IP the router thought this DHCP software assigns to this device an IP for some time (called lease time).
For all this to happen your computer/device must be set to GET IP from DHCP. Then all is done automatically and getting internet access. Usually if setup is correct on router every connect device gets:
Device IP, Subnet, Default Gateway, DNS Server 1 IP, DNS Server 2 IP, Lease time.
Hope this helps. If need anything else please do not hesitate to ask.