Homepage Show
Accessibility links
BBC Account Notifications
More menu Search Bitesize Search Bitesize
BITESIZE
GCSE Eduqas Data structures and data typesVariables, constants and arrays form the basis for how data is stored within a program. They must be declared with meaningful identifier names and appropriate data types that match the data. Without the correct data structures and data types, programs will not work. Part of Computer Science Computational thinking and programming
quiz Test
Variables and constantsPrograms usually use data in some shape or form. Data in programs is usually referred to as values. VariablesA variable is a named memory location that holds a value. The value held in a variable can - and usually does - change as the program is running. Variables make it easy for a programmer to use memory locations. The computer keeps track of which memory location the variable refers to. All the programmer has to do is remember the name of the identifier the variable was given. Declaration and assignmentMost programming languages require a variable to be identified before a value is assigned to it. This is known as declaring a variable: score is integer
This would declare a variable called Giving a variable a value is known as assignment. A variable must be assigned a value before it can be used. For example: set score = 0 This would assign the value 0 to the variable Some programming languages, such as Python, enable variables to be declared and assigned a value in the same line of code. ConstantsA constant allows a value to be assigned an identifier name. Unlike a variable, the value assigned to a constant cannot be changed whilst the program is running. Constants are useful because they are declared and assigned once, but can be referred to over and over again throughout the program. They are used for values that are unlikely to change, for example:
GCSE Subjects
What are the memory locations are available to store the values?Variables are usually stored in RAM. This is either on the heap (e.g. all global variables will usually go there) or on the stack (all variables declared within a method/function usually go there). Stack and Heap are both RAM, just different locations. Pointers have different rules.
What refers to named memory locations of the program?Identifiers are descriptive names that are mapped to locations in the computer's memory. Once a memory location is given a specific name, we can refer to that location using the identifier rather than the numeric address.
What is used by value types to store value in memory locations?Variables are nothing but reserved memory locations to store values.
Which part of a script is a named memory location which stores data of a specific type?A variable is a named storage location in the computer's memory that contains data, such as a number or a text string. The data contained in a variable is called the variable's value. Variables give you a way to store, retrieve, and manipulate values using names that help you understand what the script does.
|