An often asked question on the Internet, but if you want a scientific view of the issue, look at:
http://onlinelibrary.wiley.com/doi/1...g.342/abstract
Efficacy of firearms for bear deterrence in Alaska†
Interesting read, not much difference between long arms and handguns but also check out the caveats by the author.
NO, they did not study whether the bear took the gun and stuck it --- before someone makes that joke again.