02 Section 5 - Data types, operators,constants, variables and strings Flashcards
What are the main five data types of programming languages?
Integer Real (or float) Boolean Character String
What is the pseudocode for Integer data type?
INT
What is the pseudocode for Real data type?
REAL
What is the pseudocode for boolean data type?
BOOL
What is the pseudocode for character data type?
CHAR
What is the pseudocode for string data type?
STRING
What is the characteristics of the integer data type?
Whole numbers only
What is the characteristics of the real data type?
Numbers that have a decimal part
What is the characteristics of the boolean data type?
Can only take one of two values, usually TRUE or FALSE
What is the characteristics of the character data type?
A single letter, number, symbol
What is the characteristics of the string data type?
Used to represent text, it is a collection of characters
What are the features of the different types of data types?
- different data types are allocated different amounts of memory
- using correct data types make code more memory efficient, robust and predictable
What are weakly typed programming languages?
Languages that will try to convert data types to avoid errors, however this can lead to unpredictable errors
What are strongly typed programming languages?
Languages that won’t try to convert data types and so will produce more errors but more predictable results
How much memory does an integer data type take up?
2/4 bytes
How much memory does a real data type take up?
4/8 bytes
How much memory does a boolean data type take up?
1 bit is needed but 1 byte is normally used
How much memory does a character data type take up?
1 byte
How much memory does a string data type take up?
1 byte for every character in the string
What is casting?
Changing the data type
-languages have functions that let yopu manually convert between data types
What commands can you use to convert between data types?
int()
float()
bool()
str()
What commands can you use top convert between ASCII numbers and characters?
ASC()
CHR()
What are arithmetic operators?
Arithmetic operators take two values and perform a maths function on them
What are the different arithmetic operators?
addition subtraction multiplication division exponential quotient remainder(modulus)
What is the exponential operator?
Used to raise a number to a power
What is the quotient operator?
Returns the whole number part of a division
What is the modulus operator?
Gives the remainder of a division
What is the typical operator for addition?
+
What is the typical operator for subtraction?
-
What is the typical operator for multiplication?
*
What is the typical operator for division?
/
What is the typical operator for exponentiation?
^ or **
What is the typical operator for quotient?
DIV
What is the typical operator for modulus?
MOD or %
What is the assignment operator?
=
used to assign values to constants or variables
What are comparison operators?
==, <>, !=, , <=, >=
they compare the expression on their left hand side to the expression on their right hand side and produce a Boolean value (true or false)
What is the comparison operator to show something is equal to?
==
What is the comparison operator to show something is not equal to?
<>
!=
What can data values be stored as?
constants or variables
What does the name of a constant or variable link to?
a memory location that stores the data value
-the size of this memory location depends on the data type
What is a constant?
A constant is assigned a data value at design time that can’t be changed
What happens if you try to change the value of a constant in a program?
the interpreter or compiler will return an error
What is a variable?
A memory location for data to be stored which can change its data value during the running of the program
When do constants and variables need to be declared?
at the start of a program
What are reasons for assigning values as constants?
- if they don’t need to be changed during the running of a program
- if the value was changed, you’d only need to change it at the declaration of the constant rather than throughout the code
How can you declare constants and variables?
Examples of declarations of constants: CONST name = data CONST name as DATA TYPE = data Examples of declarations of variables: VAR name as DATA TYPE = data DATA TYPE name = data
How are strings written?
Strings are usually written inside double quotation marks “, but some times single quotes are used ‘.
What is concatenation?
When strings are joined together to form new strings
-using the + operator
What are the character in a string numbered as?
The characters in a string are usually numbered starting at 0
What are examples of common string manipulation?
x.upper
x.lower
x.length
x[i]
x.subString[a, b]
What is the operation of the function x.upper?
changes all the characters in string x to upper case
What is the operation of the function x.lower?
changes all the characters in string x to lower case
What is the operation of the function x.length?
returns the number of characters in string x
What is the operation of the function x[i]?
extracts the character in position i from string x
What is the operation of the function x.subString[a, b]?
extracts a string starting at position a with length b from string x