there is no "logging in and out" of what's app.
there is "verifying your phone number" or "deleting the app" (or deleting app data both of which will force a new verification) or "deleting your account".
verifying your phone number is the same as connecting your account (based on your phone number) to that particular installation on that particular phone.
it's a little tricky when you change the sim card in a phone without taking one of the above actions. or when you change phones but keep the same sim card. or even trickier when you change phones and sim cards.
if you give your phone where what's app is installed to someone without deleting the app (or app data) or deleting your account or verifying your account on your new phone they will continue to have access to your what's app just as if the phone was in your hands..
what's app does not know whose hand is holding the phone that it's connected to.
even if you remove and keep your sim card and give the phone to someone without your sim card installed there will be no "automatic" effect on your what's app account installed on that phone. if you give your phone AND your old sim card with the same number on it to someone they would be able to re-verify your account since they have the same number even if you deleted the app. they may or may not be able to access historical data depending on whether or not you made backups, but contact info and group settings should reappear unless you have "deleted" your what's app account before handing over your phone and phone number.