2.2.1

Variable Declaration and Assignment

Test yourself

Variable Declaration and Assignment

A variable must be declared before a value can be assigned.

Illustrative background for DeclarationIllustrative background for Declaration ?? "content

Declaration

  • Before variables can be used, they must be declared.
  • Declaring a variable means telling the computer:
    • What the identifier (name) should be.
    • What type of data will be stored.
Illustrative background for AssignmentIllustrative background for Assignment ?? "content

Assignment

  • Changing the value stored inside a variable is called assignment.
  • The value assigned to a variable must match the data type of the variable.
Illustrative background for Language specificsIllustrative background for Language specifics ?? "content

Language specifics

  • Some languages don’t need you to declare variables before you use them:
    • These languages automatically declare the variable before the first assignment.

Jump to other topics

1Computer Systems

1.1Systems Architecture

1.2Memory & Storage

1.3Computer Networks, Connections & Protocols

1.4Network Security

1.5Systems Software

1.6Ethical, Legal, Cultural & Environmental Concern

2Computational Thinking, Algorithms and Programming

2.1Algorithms

2.2Programming Fundamentals

2.3Producing Robust Programs

2.4Boolean Logic

2.5Programming Languages & IDEs

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson