You may not see a bear during your visit because bears naturally avoid people. If you do see a bear, what you should do depends on the situation. In any case, always let a ranger know or leave a message at 209/372-0322.
If you are in a developed area (e.g., campground, parking lot, lodging area) or if a bear approaches you, act immediately to scare it away: make as much noise as possible by yelling very loudly (don't worry about waking people up if it's nighttime). If you are with other people, stand together to present a more intimidating figure, but do not surround the bear. Bear spray/pepper spray is not allowed in Yosemite.
The intent is not to harm the bear, but to scare it from the area and restore its natural fear of people by providing a negative experience.
If you see a bear anywhere else, keep your distance (at least 50 yards, or about the distance four shuttle buses parked end to end would take up). If you get closer, you will be helping the bear become used to being around people.
Bears that become comfortable around people lose their natural fear of us and sometimes become too aggressive; sometimes they then have to be killed.
When a ranger sees a bear, the ranger may use non-lethal aversive tactics to chase the bear out of a developed area. During your overnight stay, expect to see and hear rangers patrolling public areas for bears. You may hear rangers yelling at and chasing bears. You may also see or hear rangers shooting noisemakers or non-lethal projectiles (such as rubber slugs from a shotgun or clear paintballs from a paintball gun). The intent is not to harm the bear, but to scare it from the area and restore its natural fear of people by providing a negative experience.
NOTE: These regulations and precautions help decrease the chance of personal injury or property damage. However, bear damage and confrontations are still possible even when all of the above guidelines are followed. Failure to comply with these regulations may result in citation and/or impoundment of property.