Why do we need to declare ports as input/output?
With the the DATA direction register bits when clear (like after reset) configure the port as an input, in this state the output register bits control the pull-up, giving you in effect a very weak output drive.  if you don't need a strong drive (eg you just want to drive the base of an NPN transistor) then in this state the port can be used as an output.

But if you need more than a few hundered microamps you'll need to set the direction register to output.