Capacitors in shock pens are used to store energy, which is essential for generating a high voltage. The primary components involved are an inductor and a switch; current flows through the inductor until the switch interrupts the flow. This interruption leads to a rapid change in current, producing a large voltage as described by the formula V = L * dI/dt. The capacitor then releases this stored energy to create the shock effect. Understanding these components is crucial for grasping how shock pens operate.