When you "give away your location" you are no longer hidden, but might still be unseen
Skip to the summary at the bottom if you don't want to wade how the above conclusion is reached.
I found this to be a very interesting question and one that was not easily answered. I suspect the reason for much of the difficulty is that
A) the designers expressed that they wanted to keep the rules of hiding simple, so that they didn't include a ton of rules for all the corner cases, which would have made the most common simple case hard to remember: (https://dnd.wizards.com/articles/features/james-haeck-dd-writing 42:54), and
B) they designers like to not repeat rules, and just expect you to know them all and combine them when appropriate (this is evidenced by anyone that has ever read the rules or seen the many questions on this site and other forums. Occasionally stuff is repeated, but that is more the exception.)
In order to unravel the answer to this question I'm going to list out all the rules I found relevant to my answer, as RAW and quotes were requested.
All rules quotations refer to the Basic Rules version 1.0, which is the version I'm using and are noted with (BR ###) where ### is the page number in that version's PDF.
One of the most important things to understand in order to answer this question is to know what hiding is, and to understand that it is not equivalent to being unseen.
Hiding requires that you cannot be clearly seen for some reason
You can’t hide from a creature that can see you clearly (BR 63)
What is sufficient to permit being able to hide?
Here are just some of the various ways that a creature can try to hide:
A) Be heavily obscured. Technically this isn't actually listed in the rules, but most the remaining ways below support this.
B) Be invisible.
An invisible creature is impossible to see without the aid of magic or
a special sense. For the purpose of hiding, the creature is heavily
obscured. The creature’s location can be detected by any noise it
makes or any tracks it leaves. (BR 171)
The bolded line (my emphasis) is what implies that being heavily obscured in and of itself is sufficient to be able to attempt to hide in most cases.
C) Have a feature/skill/ability that allows you to hide while lightly obscured. For example:
Mask of the Wild. You can attempt to hide even when you are only lightly obscured by foliage, heavy rain, falling snow, mist, and other
natural phenomena. (BR 17)
Other skills, features, or abilities exist that also grant the ability to hide while lightly obscured, but I won't bother trying to list them all. Again, the phrase "only lightly obscured" implies that being heavily obscured is normally what is expected in order to be able to hide.
D) Have a feature/skill/ability that allows you to hide while obscured in some other way:
Naturally Stealthy. You can attempt to hide even when you are obscured only by a creature that is at least one size larger than you.
E) The DM says you can try to hide.
The DM decides when circumstances are appropriate for hiding. (BR 63)
In fact, this last rule trumps all the others in that it requires the DM's agreement before a creature can try to hide. Therefore the other methods of hiding are subject to that requirement and serve to guide the DM's decisions, not overrule them.
The key point is that in all cases being invisible or obscured at least somewhat is generally required in order to hide.
Being unseen is a benefit of being hidden, not a requirement
In the hiding options above, only being heavily obscured or invisible makes a creature unseen.
A heavily obscured area—such as darkness, opaque fog, or dense
foliage—blocks vision entirely. A creature effectively suffers from
the blinded condition (see appendix A) when trying to see something in
that area. (BR 68)
Blinded (BR 171)
- A blinded creature can’t see and automatically fails any ability check that requires sight.
- Attack rolls against the creature have advantage, and the creature’s attack rolls have disadvantage.
The following rules generalize the benefits of blinded or heavily obscured to any situation where a target is unseen.
Unseen Targets and Attackers
Combatants often try to escape their foes’ notice by hiding, casting
the invisibility spell, or lurking in darkness.
When you attack a
target that you can’t see, you have disadvantage on the attack roll.
This is true whether you’re guessing the target’s location or you’re
targeting a creature you can hear but not see. If the target isn’t in
the location you targeted, you automatically miss, but the DM
typically just says that the attack missed, not whether you guessed
the target’s location correctly.
When a creature can’t see you, you
have advantage on attack rolls against it. If you are hidden—both
unseen and unheard—when you make an attack, you give away your
location when the attack hits or misses. (BR 76)
Note that being hidden according to the rule above grants a creature the benefits of being both unseen and unheard, rather than requiring being hidden for there to be any benefit from being unseen.
If being unseen were a requirement of being hidden, then only by being heavily obscured or invisible could a creature be allowed to hide.
You can be unseen for multiple reasons
If you are hidden, then you are unseen and unheard, and if you are heavily obscured you are also unseen from that, as well. If you then stop hiding for whatever reason, you are still unseen if you are still heavily obscured.
Therefore, if giving away your location by attacking removes the benefits of being hidden, you may still be unseen for other reasons. (See the next section for why a creature is no longer hidden after it attacks.)
This is why the rules do not say "you become visible" when you are discovered, as there may be some other status affecting you that is making you unseen (such as heavily obscured or invisible).
Instead it just says "you give away your location" after you attack (see the Unseen Attackers and Targets rules above).
A creature is not hidden if their location is known
This is one of the biggest sources of confusion in this question, but I think it is pretty simply answered by just looking at what a Wisdom (Perception) check is defined to be.
Perception. Your Wisdom (Perception) check lets you spot, hear, or
otherwise detect the presence of something. (BR 65 -- emphasis added)
To find a hidden creature the rules say to use a Wisdom (Perception) check to contest the hiding creature's Dexterity (Stealth) check.
When you try to hide, make a Dexterity (Stealth) check. Until you are
discovered or you stop hiding, that check’s total is contested by the
Wisdom (Perception) check of any creature that actively searches for
signs of your presence. (BR 63)
If a creature's location is known, then obviously its presence has already been detected, as one of the definitions of presence is:
the fact of being in a particular place
So how could such a creature be hiding? That would mean that the DM would have to ask for a skill check to detect the presence of something whose location is already known, which doesn't make any sense.
As such, something cannot be hidden while its location is known. To argue that a Wisdom (Perception) check is still required is to ignore the definition of what that check is doing.
So why do the rules use phrases like "give away your position" instead of "you stop hiding"?
In the Unseen Attackers and Targets rules, an unseen creature's location being unknown means those attacking it might automatically miss. That creature may be unseen for reasons other than that it was hiding.
By explicitly pointing out that an unseen attacker has given away their position means that the creature's target (or its target's allies) no longer have to risk an automatic miss when trying to attack back.
As such, by saying "give away your location" those rules cover more situations than just ones where the target is hidden.
Putting all the above together lets us answer the question(s) posed.
Does attacking mean you give up the benefits of hiding?
If you attack while hidden you are no longer unseen and unheard as a result of hiding, but you might still be unseen and/or unheard for other reasons (like being heavily obscured, or invisible, near a noisy waterfall, etc.)
Since the only mechanical benefit of hiding (besides your location being unknown, see next question) is being unseen, then whether you lose the benefit of being unseen depends on whether something else is making you unseen.
What are the implications of having given your location away?
As stated in the question, if you gave away your position, that means your enemies do not suffer the risk of automatically missing if they target the wrong location, regardless of whether they can see you or not.
In addition, your enemies do not need to make a Wisdom (Perception) check to detect your presence, since as they know your location they are obviously aware of your presence, which is what such a check reveals.
Therefore you are not considered to be hidden once you give your location away.
If the Hidden creature changes location is their new location also given away?
As such a creature is no longer hidden, they would be treated the same as if they hadn't tried to hide in the first place. So their new location would still be known, unless they were to attempt to hide again (subject to the DM's approval.)