So I get pulled over because a tail light is out. I get a fix it ticket for 75 bucks

(which is so gay because im supposed to notice it is out...that's what he said.) So after he gets my license and all, he then asks if I have any weed or dope on me. I didn't, so I said no, then he asks if he can search my car. I let him, but I thought they needed a warrant to search your car? What exactly are cops allowed and not allowed to do?