Search This Blog

Wednesday, 10 January 2018

Post 4 Varied Data Types

String
Strings are just lines of text and are most most commonly used to produce: Names, words and labels. Strings take up around 20 bytes of data however this is just the constant while it's usually 20 byte + 2 times the length of the string.
An example of a String: "This is a String"
An advantage of using a string is that it can hold much more characters than the data type "char" however because of this it takes up much more memory than "char" too.
Char
The Char data type is a single one-byte (16-bit) character. The data types stores this one character for future use for the program.Char stores a character from the Unicode character set which includes the variety of symbols ,accents , mathematical and technical symbols as well.
An example(s) of a Char data type: "A" , "a" , "+" , "?"
Boolean
Bools or Boolean data types are just a simple choice of whether something is true or false. They are not very large and take up only 1 bit of data. Boolean data types, as stated before, are simply the choice of whether something is true or false as such the type can only be one of two different values.
An example of a Boolean:  "True" or "False"
There is not much in the way of specific advantages for a Boolean data type apart from that if you were to use it it would help with the optimisation of your program in the way of memory and sometimes speed, however due to Boolean data types only involving either "1 or 0" or "True or False" there is a limited amount that you can do with them.
Integer
Integers are whole numbers that are either positive, negative or zero. Unlike the other data type "Real" also know as "Floating point numbers" integers cannot have decimal places and are one of the most commonly used data types in computer programming.
An example of a Integer: "5" or "-5"
The size of an integer tends to vary between either 2-4 bytes
An Integer has benefits to a point. A small integer up to a 64-bit can be very efficient represent in the underlying hardware and memory meaning that using them will be fairly quick however they have a limitation as for a lot of calculations you need to use real numbers and as such integers are not appropriate for these calculations.
Real
The "Real" data type is used to present an approximation of a real number. Because  these "Real Numbers" are not countable a computer cannot represent them using a limited amount of information. Real numbers are used in the computers computers calculations as well as integer calculations, the calculations that are preformed using the real numbers takes part in a separate section of the CPU known as the FPU or floating point unit.
An example of a Real number: "3.142..."
The size of 4 bytes for a simple float however if your wishing to create a double or long double version of the number it will got to 8 bytes then to 10 bytes.
Real numbers have a couple of advantages the first being that they can represent the values between integers and secondly is that they can represent a much greater range of values. However Real numbers do have their drawbacks as they can be slower than integer operations and may also lose precision.



No comments:

Post a Comment

Post 6 Sequence,selection and iteration

Sequence Sequencing is when the computer will run the code it receives, one line at a time from the top to the bottom of the requested prog...