Year 11 Exam  >  Year 11 Notes  >  Computer for GCSE/IGCSE  >  Variables & Constants

Variables & Constants | Computer for GCSE/IGCSE - Year 11 PDF Download

Introduction

  • Variables and constants store individual pieces of data in a program, accessible through their identifiers. 
  • Variables are mutable and can be altered during program execution, whereas constants retain their values throughout.

Declaring Variables and Constants

  • Variables are defined by specifying a data type, a name, and optionally a value.
  • Constants are declared using the 'const' keyword along with a name and a value.
  • When naming variables, adhere to specific rules across programming languages:
    • Names must start with a letter.
    • Names should not include spaces.
    • Variables can consist of letters, numbers, underscores (_), or dollar signs ($).
    • Avoid using reserved words like 'if', 'while', or 'for' as variable names.
  • Examples of data types encompass integers, floats, Booleans, and strings.

Question for Variables & Constants
Try yourself:
Which keyword is used to declare a constant in a program?
View Solution

Examples in Different Programming Languages

  • Examples in Pseudocode:

    • Declare a variable named 'score' with an initial value of 10
      score ← 10
    • Declare a constant named 'PI' with a value of 3.14
      const PI ← 3.14
  • Examples in Python:

    • Declare a variable named 'score' with a value of 10 using 'score = 10'
      score = 10
    • Declare a constant named 'PI' with a value of 3.14 using 'PI = 3.14'
      PI = 3.14
  • Examples in Java:

    • Declare a variable named 'score' with a value of 10 using 'int score = 10;'
      int score = 10;
    • Declare a constant named 'PI' with a value of 3.14 using 'final double PI = 3.14;'
      final double PI = 3.14;
  • Examples in Visual Basic:

    • Declare a variable named 'score' with a value of 10 using 'Dim score As Integer = 10'
      Dim score As Integer = 10
    • Declare a constant named 'PI' with a value of 3.14 using 'Const PI As Double = 3.14'
      Const PI As Double = 3.14
The document Variables & Constants | Computer for GCSE/IGCSE - Year 11 is a part of the Year 11 Course Computer for GCSE/IGCSE.
All you need of Year 11 at this link: Year 11
92 docs|30 tests

Top Courses for Year 11

FAQs on Variables & Constants - Computer for GCSE/IGCSE - Year 11

1. What is the difference between variables and constants in programming?
Ans. Variables in programming are used to store and manipulate data that can change during the execution of a program, whereas constants are used to store values that do not change throughout the program.
2. How do you declare a variable in Python?
Ans. In Python, you can declare a variable by simply assigning a value to it, for example: `x = 5`.
3. Can you change the value of a constant during the execution of a program?
Ans. No, constants are values that are meant to stay the same throughout the program, so their value cannot be changed once it is assigned.
4. Why is it important to use variables and constants in programming?
Ans. Variables allow programmers to store and manipulate data efficiently, while constants ensure that certain values remain consistent and unchanged throughout the program.
5. How can declaring variables and constants improve the readability of your code?
Ans. By using variables and constants, programmers can give meaningful names to values and make their code more understandable and easier to maintain.
92 docs|30 tests
Download as PDF
Explore Courses for Year 11 exam

Top Courses for Year 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Variables & Constants | Computer for GCSE/IGCSE - Year 11

,

Previous Year Questions with Solutions

,

Extra Questions

,

video lectures

,

Important questions

,

ppt

,

mock tests for examination

,

Exam

,

Viva Questions

,

pdf

,

Summary

,

shortcuts and tricks

,

Free

,

study material

,

MCQs

,

Objective type Questions

,

practice quizzes

,

Sample Paper

,

Variables & Constants | Computer for GCSE/IGCSE - Year 11

,

Semester Notes

,

Variables & Constants | Computer for GCSE/IGCSE - Year 11

,

past year papers

;