WHY DO POLICE APPROACH THE PUBLIC?
So what's going on when a police officer approaches you? Mostly (honestly) they don't care about you, they're just passing through on their way to do something or check out somebody they are interested in. A greeting, if you have it in your heart and can sound friendly, is all that's called for. But if the officer is approaching you they generally have a reason for it. I mean, if I were a cop, I probably wouldn't ever interact with anybody without a reason given that cops have to force interactions with people constantly as part of the job. (I would also not be a very good cop, I expect). That said, while I'm sure that many officers are just really friendly, I wouldn't count on the one going out of his way to talk to me being that way.
POLICE OFFICERS HAVE HUNCHES
So why do cops approach people? 1) Suspicion and 2) also Suspicion, just assume that it's always suspicion and act accordingly to protect yourself. Example, if you're in a parked car and an officer is approaching he is either fixing to tell you to leave or he already thinks you're up to something worse and wants to find out what. If some crime just occurred in the vicinity then he might be seeking information; did you see it? (Did you participate in it?) He could also be bored, but never count on this because it will never work out in your favor. Assume the officer is trying to assess what you are doing unless there is some other obvious reason for the interaction (like you called the cops).
When an law enforcement officer (LEO) is figuring out what you're up to they are generally working on a hunch. Something seems "off" or unusual to them and they want to learn why they think that is. Your best course of action is to leave. Leave calmly, but leave. Don't get nervous. Don't leave your stuff behind, but do leave. Just act like everything's cool and you've got an appointment to get to. This applies even if you know you've done nothing wrong.
The hunch part is important because if that's all they've got then they can't detain you. In legal terms an LEO has to have an articulable suspicion that you are committing or have committed some crime before they can arrest or detain you. An articulable suspicion most just means "reasons". Once an LEO has talked to you for a minute most of them can come up with a reason to detain you for further investigation. Nervousness is one such reason. So try not to give that to them.
As long as the police officer has no more than a hunch then you are supposed to be free to leave at will. They cannot force you to have a conversation with them, so don't other than to ask if you can leave. I would generally say good bye and head towards the exit. If you decide to have a voluntary conversation then anything you say is admissible in court against you.
"HOLD UP THERE"
So what happens next? You take my advice and try to leave and the officer says "Hold up there, I need to talk to you." At this point, although you can't leave (not safely anyhow), you're not required to speak to the police other than to accurately identify yourself. If they have detained you then it should be on some describable suspicion of a crime. Indicate that you do not wish to speak to the police without a lawyer present.
SUSPICION OF WHAT?
A typical example of a suspicion would be suspicion of carrying contraband, like drugs or weapons. The officer is probably trying to develop probable cause to arrest you and can do things like pat you down to ensure his own safety. That pat down is something to be avoided because if they feel anything unusual they can then examine it without this legally amounting to a search requiring a warrant. That's why you want to make every effort to leave. Of course, if they find contraband then you will likely be arrested for possession of the contraband and taken to the jail. Even so, at no point should you make any statements other than identifying yourself and requesting access to a lawyer. Remember this, most suspicion is generated by the statements of people that the police are talking to.
EVERYBODY TALKS TOO MUCH
TLDR: Don't talk to the police. Don't volunteer any information and attempt to leave unless commanded to stay. If you are commanded to stay then you should stay but you shouldn't talk about anything other than to identify yourself, indicate you don't have anything to talk about without access to an attorney, and request to leave. If you talk at any point it is generally pretty difficult to get it suppressed later if it leads to a charge even if they haven't read you your rights.