A passing exercise (a PASSEX in U.S. Navy terminology) is an exercise done between two navies to ensure that the navies are able to communicate and cooperate in times of war or humanitarian relief.
Common drills include flashing light drills, semaphore drills, and flaghoist drills. In modern times, navies within a very close alliance may include electronic and digital cooperation including using electronic communications and target acquisition. Some exercises between the French and US navies (particularly in support of the war in Afghanistan) have included carrier-based fighter-bombers "touching down" (landing then taking off) on each other's carriers in order to ensure interoperability.
While the official reason of a PASSEX is to practice cooperation, various unofficial reasons might be to "show the flag" (show the power of a nation through a public display of naval power) or other political or diplomatic reasons.