score:3
This depends a lot on your nationality. If you need a visa you will probably need to get a tourist visa for the UAE.
From https://u.ae/en/information-and-services/visiting-and-exploring-the-uae/transit-visa
Only the UAE based-airlines you are travelling through can arrange your transit visa prior to your journey. If your trip is through a travel agency, the agency can also help you get the visa, but all visas are routed through the airline. Airline agents can apply online for transit visas through one of the following means:
This says that the airlines needs to arrange the transit visa for you. They will only do this if you both arrive and depart with the same airline. If you use two unaffiliated airlines, there is no reason for either one of them to get you a transit visa.
Now, according to UAE rules, a transit visa up to 48 hours is free, so I wonder if I can use it or I will have to apply for a tourist visa.
You will have to apply for a tourist visa.
Also, will it be necessary to have the visa if I just want to stay at the airport or can I just leave the first flight, check in for the second, and go on my way to B without any visa?
You will need a visa. Even if it's technically possible to do an airside self connection, the first airline will not let you board without proper papers.
You can always call the first airline and ask if they would arrange a transit visa for you, but in all likelihood they will refuse. They can't easily verify your connecting flight and they have no way of knowing if you will actually take the flight.