7.1.1
Programming Fundamentals
Variables and Constants
Variables and Constants
We may need to store data in the memory as part of our program.
The memory
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.
Variables
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.
Constants
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.
Assignment
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
Comments are lines of code that are ignored completely by the computer.
Purpose of comments
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.
How to comment
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
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.
Input
Input
- Input is collecting data, usually by the keyboard.
- This is written in pseudocode as:
- variable = input("Please enter [something]...")
Output
Output
- Output is putting data to the screen, usually as text.
- This is written in pseudocode as:
- print("Text goes here")
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction
Jump to other topics
1Components of a Computer
1.1Structure & Function of the Processor
1.2Types of Processors
2Software & Software Development
2.1Systems Software
2.2Applications Generation
2.3Software Development
3Exchanging Data
3.1Compression, Encryption & Hashing
3.3Networks
4Data Types, Data Structures & Algorithms
4.1Data Types
5Legal, Moral, Cultural & Ethical Issues
5.1Computing Related Legislation
6Elements of Computational Thinking
6.1Thinking Abstractly
6.2Thinking Procedurally
6.3Thinking Logically
7Problem Solving & Programming
7.1Programming Techniques
7.2Programming Construction
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
What are comments?