(2-part post):
I used to run a large railway station. I got asked this question several times per day (usually by people who'd arrived at the very last minute for their train!).
With the exception of special services (such as Gatwick Express), you're always expected to purchase a ticket prior to boarding any train. (Obviously, that doesn't apply at unstaffed stations). It's actually a criminal offence to board a train, without a ticket, if you've been presented with the opportunity to buy one prior to travel.
In some parts of the country, particularly in the former 'Network South-East' area, you have to pay a penalty fare if you're found to have boarded without a ticket.
Where rail companies don't impose penalty fares, the rule is that you'll be charged for an Open Single, or Open Return, ticket. If you're travelling at peak times, that might mean that you'll pay exactly the same 'walk-up' fare that you'd have paid at the ticket office. However, you won't be able to purchase Saver or Cheap Day tickets at off-peak times.
For example, if you turn up at Norwich station requiring a peak-time Standard class return ticket to London, for immediate travel, it will cost you �66 for an Open Return. If you buy it on the train, it will still cost you �66. However, if you travel off-peak, to & from Norwich, it will cost you �38 at the ticket office (for a Saver Return) but �66 on the train (for an Open Return).