well I sure hope you will have a contract, and it should say something about code ownership. Absent anything about it, you will usually retain all rights on the code.
It would take a pretty sizable sum for me to code something for someone and then transfer them all of the rights on it, since you would basically have to code everything from scratch to be able to do that.
In all of my contracts it clearly states that I own all the rights to the code and grant the client a license to use it. Unless you are going to be paying me enough to live off of for a few years, that is the way I work (and that is the way it works in reality as well). Now I will give up rights on a few things, for example if the company needs some component added that contains some algorithm or something that is part of their competitive advantage or trade secret, then I usually will transfer them the rights on that component. Since my app is plug-able, and most non critical components are plugins, I make the client component a plugin as well, so since it stands "apart" from the rest of the application, it is easier to transfer the rights on that part of the application since the lines are clearly drawn. Doing something like that would be much tricker if all of the code was mixed together. In that case, I'm not even sure it would be doable since there would be no clear separation between code you own and code you transfer ownership of to them.
Incidentally I don't make my apps plug-able for legal reasons, but to give flexibility... but it seems part of that flexibility is legal flexibility as well.
You can also transfer them ownership of the code, but retain ownership of your "developer tools" which can include your nuts and bolts code. This is also common.
Anyways, make sure you have a contract with them before even thinking about starting work, and make sure it covers all major bases, including code ownership, and make sure the scope and specs are worked out prior to signing. It can take awhile to get all the details worked out with a client, but both of you will be standing on much better ground.
Oh yes and you really either need to speak with a lawyer (if you can afford it), or get yourself a software developer legal kit. I've got Nolo's web & software dev legal kit and it was worth every penny a thousand times over. Of course there is no substitute for getting an attorney to personally look at your situation, but IMO as long as you and the client clearly understand each other and can hash out a decent agreement among yourselves, there isn't a great need to bring in an attorney.