When stopping you for a routine traffic violation, a police officer is generally not allowed to search the vehicle. There are, of course, exceptions. The right to privacy is governed by the Fourth Amendment: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no Warrants shall issue, but upon probable cause, supported by Oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.
However, the Supreme Court ruled that automobiles are an exception to the Amendment, and can, provided probably cause, be searched without a warrant. That is, while a police office would generally need a warrant to search your vehicle, if he/she has a good reason to believe that you may be dangerous, concealing a weapon or illegal objects, or committing a criminal act, then your vehicle can be legitimately and legally searched. The reason that cars are an exception is twofold. First, people expect less privacy in a car than they do in a house. Second, a car is mobile, making it impractical to require a warrant; any illegal objects could be disposed of quite easily before a warrant was attained.
Examples of probable cause include empty or open containers of alcohol, the smell or sight of marijuana, the driver or passenger shoving something under the seat in a panic, etc. These suspicions can be articulated. It should be noted that whether there was legitimate probable cause is often contested in court.
If an officer asks to search your vehicle, you have the right to refuse. The vehicle can only be searched with your consent, a warrant, if you are arrested, or with probable cause. You should know these rights and ask the officer on what grounds he/she is searching your vehicle. If the officer proceeds with to search without your consent, do not attempt to stop him/her. If the matter goes to court, you will be able to challenge the search, claiming it was done illegally. If this is the case, any evidence found because of the illegal vehicle search is invalid.