paper 2 - section 5 - programming Flashcards
name 5 different data types
- integer
- real (or float)
- boolean
- character
- string
what is the pseudocode for an integer?
int
what is the pseudocode for a real (or float)?
real
what is the pseudocode for boolean?
bool
what is the pseudocode for character
char
what is the pseudocode for a string?
string
what type of data do integers hold?
whole numbers only
what type of data do reals (or floats) hold?
numbers that have a decimal part
what are the characteristics of boolean data types?
they can take one of two values, usually true or false
what type of data does the character data type hold?
a single letter, number or symbol
what type of data do strings hold?
a collection of characters - strings are used to represent text
what are the benefits of using the correct data types?
using the correct data types makes code more memory efficient, robust and predictable
Each data type is allocated a different amount of memory. how much is the typical amount of memory taken up for an integer?
2 bytes or 4 bytes
Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a real (or a float)?
4 bytes or 8 bytes
Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a boolean value?
1 bit is needed but 1 byte is usually used
Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a character?
1 byte
Each data type is allocated a different amount of memory. What is the typical amount of memory taken up by a string?
1 byte for every character in the string
what is the difference between weakly typed and strongly typed languages?
weakly types languages will try to convert data types to avoid errors, however this can lead to unpredictable results.
Strongly typed languages won’t try to convert data types and so will produce more errors but more predictable results.
what is casting used for?
it’s used to change the data type
programming languages have functions that let you manually convert between data types. What is this known as?
casting
name 4 commands that can be used in casting
- int()
- float()
- bool()
- str()
what does the function ASC( ) do?
allow you to find the ASCII number of characters (e.g. ASC(“b”) would convert the character “b” into its ASCII number 98)
what does the function CHR( ) do?
it allows you to convert an ASCII number into a letter (e.g. CHR(98) would convert the ASCII number 98 into its equivalent character “b”)
what do the arithmetic operators do?
they take two values and perform a maths function on them
what does the DIV operator do?
returns the whole number part of a division (not the remainder)
what does the MOD operator do?
it returns the remainder of a division
what is the typical operator to find a quotient?
DIV
what are the typical operators to perform a remainder (modulus) function?
MOD or %
what are the two typical operators for exponentiation (powers)?
^ or **
what is the assignment operator?
=
what is the assignment operator used for?
it’s used to assign values to constants or variables
what do comparison operators do?
they compare the expression on their left hand side to the expression on their right hand side and produce a Boolean value (either true or false)
what is the comparison operator that means ‘is equal to’?
==
which comparison operators mean ‘is not equal to’?
<> or !=
is it <= or =< ?
<=
is it >= or =>?
> =
is it != or =!
!=
do you use a double equals sign for assignment or comparison?
comparison`
which two things can data values be stored as?
constants or variables
what does the size of the memory location allocated to a constant or variable depend on?
the data type
when is the value of a constant assigned? can it be changed?
a constant is assigned a data value at design time that can’t be changed
what happens if you attempt to change the value of a constant in a program?
the interpreter or compiler will return an error
why are variables more useful than constants?
they can change
can you change the data type of a variable?
no, only the value
what is it called when strings are joined together to form new strings? which operator is often used to do this?
it is called concatenation, and it’s often done using the + operator
if string = “hello”, then what would string[2] be? why?
“l”, because it starts from 0
what does the function .upper do?
changes all characters in a string to upper case (e.g. if x = “Hello” then x.upper would return “HELLO”)
what is the function used to change all characters in a string to lower case?
.lower (e.g. if x = “HELLO” then x.lower would return “hello”)
what is the function used to return the number of characters in a string?
variablename.length