Why are some men nicer to other men instead of women?

I don’t know if anyone’s noticed this but some men will feel comfortable disrespecting women and being rude to them but when they get around other men or their friends they are extremely nice. They will also act tough and show off in front of them. Why do you think this happens?