pinMode or digitalWrite firrst....

Hello, Im a programmer nubie. I am working on a project where I want to make sure all the outputs are high Immediately after I boot. My question is can I do a digitalWrite before pinMode...
thanks

digitalWrite(3, HIGH);
pinMode(3, OUTPUT);

vs.
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);

Why not try both options and see for yourself?

Thanks for the reply
I have, tried. My concern is violating some arduino programming rules or convention .
The relay module Im using is reverse logic. A LOW to the module activates it. I just need to make the relay stays inactive.

thanks

Note that there are four possible states:

Output/High
Output/Low
Input/Pullup
Input/No Pullup -- this is the default state after reset

Since the input/output mode is set in the DDR (data direction register), and the output state (or input pullup resistor) is set in the PORT register, both cannot be changed simultaneously.

Therefore after a reset, it takes two steps to get to Output/High. It can be done with either code snippet as you showed. The first will briefly transition through the Input/Pullup state, and the second will briefly transition through the Output/Low state and will sink current at low impedance if a voltage is applied to the pin.

It may or may not make a difference to the connected circuitry. If it does, choose the most compatible path. In general, I would choose going through the Input/Pullup state (the first code snippet) unless I had a specific reason not to. Sounds like this is what you should do if a relay is involved, although the transition may be so fast that the relay is unable to respond for the brief transition through Output/Low.

THANKS Jack
Very complete answer. I have done it both ways. But was not sure
how do I give you a karma point

just gave the karma point

Meant to add, there are no programming rules or conventions in this case, it's more a matter of choosing which gives the best transition for the attached circuitry. Karma always appreciated, thanks. Sometimes I use the attached diagram to visualize and determine the best transition from one state to the next. For any given state, one of the three other states can only be reached by transitioning through an intermediate state.