How does cooking with whole peppercorns compare to ground? If you buy ground peppercorns you should always go for fresh ground because they taste completely different imo.

In bangladeshi cooking I notice that they use whole black peppercorns in their curry and discard it at the end.  However would using it like this be equivalent to cooking with non fresh peppercorns as above?

My thinking is that if the taste between fresh ground and non fresh ground is so different, then cooking a whole peppercorn is like non fresh because the surface has been exposed to air for a long time.

Is my thinking correct or should cooking whole be considered cooking fresh, if so in what way?
For freshness, it is always best to purchase whole spices and use whole, crack, or grind them as needed. With respect to peppercorns (or, really any whole spices) the effect will be different when they are used whole, just cracked, or ground.  The flavor will also be impacted by toasting the spices before use, and when they are added during the cooking process.  The taste difference between all of these options can be significant.  The bottom line is that you should have some idea of the effect you are trying to create with the spice, and how the treatment of that spice achieves the result you are looking for.