Chapter 2. Remember This—Memory and Variables

 

What is a program? Hey, wait a minute, I thought we answered that in chapter 1! We said a program was a series of instructions to the computer.

Well, that’s true. But almost all programs that do anything useful or fun have some other qualities:

  • They get input.
  • They process the input.
  • They produce output.

Input, processing, output

Your first program (listing 1.1) didn’t have any input or processing. That’s one reason why it wasn’t very interesting. The output was the messages the program printed on the screen.

Your second program, the number-guessing game (listing 1.2), had all three of the basic elements:

  • The input was the guesses the player typed in.
  • The processing was the program checking the guesses and counting the turns.
  • The output was the messages the program printed.

Here’s another example of a program that has all three elements: in a video game, the input is the signals from the joystick or game controller; the processing is the program figuring out whether you have shot the alien, dodged the ball of fire, completed the level, or whatever; the output is the graphics on the screen and the sound from the speakers or headphones.

Input, processing, output. Remember that.

Okay, so the computer needs input. But what does it do with it? In order to do something with the input, the computer has to remember it or keep it somewhere. The computer keeps things, including input (and the program itself), in its memory.

Names

What’s in a name?

Numbers and strings

How “variable” are they?

The new me

What did you learn?

Test your knowledge

Try it out