Wednesday, 21 September 2016

Variables and data types


Data typeDescriptionSample data
INTEGERStores positive or negative whole numbers17
REALStores numbers that contain decimal places/values and can also store integers17.65
CHARACTERStores a single character which can be a letter, number or symbol$
STRINGStores alphanumeric combinations and text. String is really a group of characters stored together as one. Numbers to be used for calculations should not be stored as string data even though they can be. They should be stored as INTEGER or REALBatman
BOOLEANStores True or False only. This is sometimes taught as 1 or 0 only where 1 is true and 0 falseTrue   

In a program, data values can be constant or variable. If values are variable they can be changed by the program and the user. When a program is run, the data values are held in memory whilst they are being worked on.
Constants:  Data values that stay the same every time a program is executed are known as constants. Constants are not expected to change.
Variables: are data values that can change when the user is asked a question, for example, their age. Variables may change during program execution.
A variable is a memory location. It has a name that is associated with that location. The memory location is used to hold data. The key difference when comparing a constant to a variable is that the value associated with a variable name may change during program execution. For example 'highScore' would need to be variable to change throughout a game.

No comments:

Post a Comment