Data Types

Cards (27)

  • Programming language can store data as different data types
  • The code for an integer is " int "
  • Integers are whole numbers only
  • The code for a real (or float) is " real "
  • A real number is a number that has a decimal point
  • The code for Boolean is " bool "
  • A Boolean data type only has one of two values , TRUE or FALSE
  • The code for a character is " char "
  • A character is a single letter , number or symbol
  • The code for a String is " string "
  • Each data type has a different amount of memory
  • What is the typical amount of memory taken up by an integer?

    2 bytes or 4 bytes
  • What is the typical amount of memory taken up by a Real?
    4 bytes or 8 bytes
  • What is the typical amount of memory taken up by a Boolean?
    1 bit is needed but 1 byte is usually used
  • What is the typical amount of memory taken up by a Character?
    1 byte
  • What is the typical amount of memory taken up by a String?
    1 byte for every character in the string
  • Using the correct data types makes code more memory efficient , robust (hard to break) and predictable
  • Weakly typed programming languages try to convert data types to avoid errors , but this can lead to unpredictable results
  • Strongly typed programming languages won't try to convert data types and so will produce more errors but also more predictable results
  • Casting is used to change the data type
  • Languages have functions that let you manually convert between data types - this is known as casting
  • what does the int("1") command do?
    It converts the string value of "1" to the integer value of 1
  • What does the real(1) command do?
    It converts the integer value of 1 to the real value of 1.0
  • What does the bool(1) command do?
    It converts the integer value of 1 to the Boolean value of True
  • what does the str(True) command do?
    It converts the Boolean value of True into the string value of "True"
  • What does the ASC(b) command do?
    It converts the character 'b' into the ASCII number 98
  • What does the CHR(98) command do?
    It converts the ASCII number 98 into the character 'b'