Dave and Papa Echo have got it right Lizardqing2.
The Type V11 U-Boat has two exaust ports near the back of the boat above the waterline[when surfaced]one Port and the other Starboard.Diesels were only used on the surface and when the Alarm was sounded the engine room crew would have to close both the inlet and outlet valves before the ballast tanks were flooded.
If the diesels were left running under the surface they would suck in all the air within a couple of minutes.
Papa Echo mentioned the snorkel sytem which allowed U Boats to run on diesels just under the surface,the snorkel device had both the air intake and the exaust outlet within the same housing.
The Germans also came up with a U boat design that used some sort of closed peroxide engines called the Walter engine i think,which allowed the U boat to run under the surface without having to surface to charge the batteries.
The Walter engines proved to be unreliable and dangerous so they were never widely produced. J.S.