7.1.1

Programming Fundamentals

Test yourself

Variables and Constants

We may need to store data in the memory as part of our program.

Illustrative background for The memoryIllustrative background for The memory ?? "content

The memory

  • The memory can be thought of as split up into 'blocks' called words.
  • Each word is usually 32 or 64 bits long.
  • To access a piece of memory, you have to use its memory address which looks something like 0x9FFF:000F.
Illustrative background for VariablesIllustrative background for Variables ?? "content

Variables

  • To make life easier for programmers, we can give a memory location a symbolic name called an identifier.
  • The identifier is a word which describes what we will store in that memory location.
  • A variable is any part of the memory that we have named, and that we can change the value of while the program is running.
Illustrative background for ConstantsIllustrative background for Constants ?? "content

Constants

  • A constant is a named location in memory that can be used to store a value which does not change while the program is run.
Illustrative background for AssignmentIllustrative background for Assignment ?? "content

Assignment

  • The process of setting a value to a variable or a constant is known as assignment.
  • Assignment is usually shown using an equals sign, e.g:
    • height = 39.

Comments

Comments are lines of code that are ignored completely by the computer.

Illustrative background for What are comments?Illustrative background for What are comments? ?? "content

What are comments?

  • A comment is a line of code that is completely ignored by the computer.
Illustrative background for Purpose of commentsIllustrative background for Purpose of comments ?? "content

Purpose of comments

  • Comments can be used to add description to your code to make it easier for other people to understand.
  • They can also be used to leave notes and reminders to yourself as you work on a complex program.
Illustrative background for How to commentIllustrative background for How to comment ?? "content

How to comment

  • To write a comment in most languages, you must use a special character which tells the computer to ignore the rest of the line:
    • In Python, that character is a #.
    • In C-style languages it is //.
  • The exact character depends on the language being used.

Input and Output

We need some method of getting data into and out of the computer. That's where input and output commands come in.

Illustrative background for InputIllustrative background for Input ?? "content

Input

  • Input is collecting data, usually by the keyboard.
  • This is written in pseudocode as:
    • variable = input("Please enter [something]...")
Illustrative background for OutputIllustrative background for Output ?? "content

Output

  • Output is putting data to the screen, usually as text.
  • This is written in pseudocode as:
    • print("Text goes here")

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Procedurally

6.3Thinking Logically

7Problem Solving & Programming

8Algorithms

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