Officers can ask, and whether they do depends on the country, your nationality, and how your answers at the counter go. Most travellers pass through with no accommodation questions, but the moment an officer wants reassurance, having something to show transforms the interaction, so carry at least the first few nights' confirmation.
What is accepted is fairly consistent: hotel or hostel bookings (printed or on your phone, though some countries prefer paper), a rental confirmation, or, if staying with friends or family, an invitation letter with the host's address and contact details. Several countries formalise the invitation route, requiring hosts to register the visit or provide an official invitation, particularly for visa applications, so check whether your destination is one of them.
If your plans are loose, book a refundable first night to satisfy both the airline and immigration, then travel freely afterward. Vague answers with no booking is the combination that earns secondary questioning, so at minimum know where you are sleeping on night one.