Some of the info in the above posts might need to be clarified a bit.
Using digitalWrite() while a pin is not in OUTPUT mode will not set the future output level. This is because historically, Arduino did not have INPUT_PULLUP and INPUT_PULLDOWN...
MarkT is correct and describes how to achive the goal. However, if your circuit or the hardware that connects with your circuit does not have a built-in pull-up resistor, you can use pin mode INPUT_PULLUP when the pin is an input to reduce the...