7.1 Programming Fundamentals Flashcards
What is a data type
Values than be used in a data item
Give some data types
Integer, float/real, character, string, Boolean
Integer
Whole numebers
Typical amount of memory for integer
2 bytes
Float/real
Number with a fraction part (1.3, 20.0)
Typical amount of memory for float/real
4 bytes
Char
A single ASCII char such as A, b, !, 3 and Space
Typical amount of memory for a char
1 byte
String
0 or more chars
Typical amount of memory for string
1 byte per char in string
Boolean
True or False
Typical amount of memory for a boolean
Theoretically 1 bit, but in high level languages often 1 byte
Difference between variables and constants
Variables can be changed while running and constants can only be changed before the program is run.
Input Statement
A way to gather inputted information from the user via the CLI (Command Line Interface)
Give some arithmetic operators
+, -, *, /, DIV, MOD
DIV
Used for integer division (quotient)
MOD
Modulus is used to find the remainder when dividing one integer by another
What rules do arithmetic operations follow?
BIDMAS (Brackets, indices, division, multiplication, addition, subtraction)
What is the difference between the way the integer 17 is stored and the string “17” is stored?
17 is stored as binary 17, whereas the string “17” is stored as the string of “1” and then the string of “7”
Casting
Functions to change the datatype of one variable to another
Examples of casting functions
- int()
- float()
- str()
- bool()
- ASC()
- CHR()
- b()
What is string concatenation?
The operation of joining and manipulating the data held in strings
What will “6” +”3” add to?
63 (because they are strings which means they are concatenated together)
Give some string handling functions (written in python)
len(string) string[x:] string[:x] string.upper() string.lower()
Why should you use comments?
- To describe the purpose of the program
- To state the author of the program
- To explain what the code does
(Comments are ignored when your program is translated to machine code and executed)