Is it imperative that the variables be declared with assigned values?
Could someone please explain to me why or why not?
Some students declared their’s without assigning and intial value and it worked just fine. I know they’ll ask me why it matters and I don’t know how to answer that!
Thanks for any help!!
If you reference a variable before it is assigned a valid value bad things can happen. Two options to avoid that are; write your code so that you don’t use a variable without assigning it something first, or initialize your variables to something harmless or default before the program does anything. With a third option being lazy init which AP CSP doesn’t cover.
The first option is a better way to program. But at this level either way is fine.