Usually, players are not supposed to know how hard it is for them to overcome the obstacles they face.
(While this is valid for every D&D edition I know of, examples will be about the editions I'm most familiar with, which are D&D 3.5e and D&D 4e)
- Most DCs for things you want to do are fixed by the rules and everybody knows them. A DC 15 tumble check to avoid provoking AoOs in D&D 3.5e is known by everyone and players often optimize their character's tumble ranks to auto-pass that roll. That's usually rolls against well known DCs (how hard it is to smash through a common house door) or rolls that involve no external opposition (a concentration roll to cast on the defensive only involves the level of the spell that same player decided to cast, thus the player already knows the DC - a roll to escape from manacles depends instead on how good the manacles are).
- Players can often understand which is the DC for their rolls if they can get more attempts at beating the same DC. Determining the AC of an enemy is a prime example of this and this in turn might lead to tactical choices like setting the right To Hit penalty to Power Attack - a 3.5e feat that lets you sacrifice precision to gain damage. Finding out the DC so you can use it for tactical choices is rewarding to some players.
- Sometimes you don't want your players know if their characters "made it": is the door protected by a trap? If it is and the characters don't know but the players do, somebody might find an excuse to send the tank forward or to be unusually suspicious*.
- It's pretty common, in my player and DM experience, to hide even the roll's result in such an event (the DM rolls for the players, asking them the modifiers), so they won't meta-play on a particularly low or high roll that might easily mean failure or success for a wide range of DCs.
- Sometimes, the DM will be rolling in secret (or using the first element in a list of pre-rolled d20s, so the players never hear him rolling) to avoid players even knowing that a roll is happening. Someone rolling Spot to spot a tattoo on the wrist of the guy he's speaking with is a prime example. Knowing there was a roll and having failed it might worry players when their characters have never had any reason to. If everybody fails, this option might make for a more immersive experience**.
A DM I talked with some years ago told me that D&D 4e, that's perfectly suitable for a "hide your DCs" kind of approach, also works with public DCs for everything. True, that's a bit of meta-gaming*, because characters can't really know what their enemy's defenses are, but it makes the game more tactical, allowing players to choose their attack powers according to the different chance of actually hitting.
This is not what all players want from their game and while it can easily be done for every D&D game, it trivializes choices (I already wrote about 3.5e Power Attack and the satisfaction in finding out the optimum ratio of precision/damage each combat: revealing the target's AC turns this into a boring "look at the table, set the value" problem. Not revealing it, on the other hand, might displease players who don't like losing turns to get to that optimum).
D&D assumes most DCs - at least those relative to factors external to the character like AC of enemies, trap DCs, opposed checks - are not known to the players.
D&D does not break if you rule the opposite to be true, but it sure provides a very different gaming experience. Ask your group what they'd be comfortable with.
(*) This is called meta-gaming. In D&D-like games, meta-gaming is often a problem because there's not a direct correlation between failing a roll and suffering the consequences. In the trap example a failure might work this way:
1. The character fails a Search roll and believes there's no trap on the door.
2. The character decides to walk by the door.
3. The trap springs.
As you can see, step 2 is not related with step 1, so if a player suspect there is a tra (because he checked for one and rolled low) he might find excuses to avoid step 2 for unrelated reasons, never getting to step 3.
Another common meta-gaming issue is when a player does not recognize a monster with his Knowledge skills but uses the most effective tactic against it because he knows its vulnerabilities. Do you hit the red dragon with your max damage fireball that will deal no damage, wasting a turn because you failed the check, or do you cast your otherwise subpar ice spell, meta-gaming?
Some different games have this decision forced by the failed roll and are not this vulnerable to meta-gaming. All this to say meta-gaming isn't inherently bad, even if in this game it usually is.
(**) On the other hand, some games teach us it's good if players know even things their characters did not realize, because they can move their characters in a way to exploit the character's lack of knowledge and letting it become more relevant to the story. That's something you might want to do if your players are interested in creating a story and (since D&D has no safety nets to save characters whose players voluntarily take risks) don''t really care about keeping players alive.
Any player who does character advocacy and tries to make in-game choices that will preservate his character's survival is almost doomed to use that knowledge to meta-play instead. The game itself tells him it's the only good choice he has. (Hiding the rolls might make the story less understandable but saves the rest of the game.)