Depends on the system, style, and context.
For example, if I'm casting a spell on a victim in 5e, I know what the DC is.
For something like "finding the trap", in D&D that's pretty open to the GM. I usually tell players the target number before they roll, so they can better decide if they want to use more resources or rethink.
Other systems might have more specific rules.