Data Types
DATA TYPES
While solving a problem, we come across different types of data to be referred to. These types of data are divided under different “Data Types” in different programming languages.
Most of the languages use primitive data types which include:
Byte: Interger values. 8 bit long. With a minimum value of -128 and maximum of 127
Short; Interger values. 16 bit long. With a minimum value of -32,768 and maximum of 32,767
Int: Interger values. 32 bit long. With a minimum value of -231 and maximum of 231-1
Long: Interger values. 64 bit long. With a minimum value of -263 and maximum of 263-1
Float: Decimal Values. 32 bit long.
Double: Decimal Values. 64 bit long.
Boolean: True or False
Character: 16 bit long. Single alphabet, symbol or digit where digit is not treated as a number i.e. you cannot perform arithmetic calculations over it. Characters are stored as unicode in the computer memory. A character value is written within single quotes. For example: ‘A’, ‘9’,’&’, etc. Here, A is a character and so is the digit 9. Digit 9 will not be considered as an integer when it is used as a character.
Apart from primitive data types, there are other data types also:
String: Combination of alphabet, symbol and digits. A string is written within double quotes. This essentially means anything that is surrounded by double quotes is a string. Even if we write a single character within double quotes it will be treated as a string and not as a character. For example: “A”, “9”, “Hello World”, etc. These are all individual strings.
Note: A string can contain spaces.
Arrays: collection of data of the same data type. This means a collection of values, which can be variable or constant. This collection needs to be of the same type. For example, an int array would contain only integer values and a string array would contain only strings. An int array cannot contain a string value and vice versa.
Suppose we have 5 names to be stored in the array for Friends. Since the names are a combination of characters, so it will be a string array. The names of five friends are: “Ann”, “Helen”, “Liza”, “Monica” and “Suzie”.
What is the length of an array?
Length of the array (n), is equal to the number of elements in an array. Since we have names of five friends, so the size of the array is 5, i.e. n=5. This is also known as the size of the array.
What is array index?
Array index is the position of an array element within the array. When we store the name of all the friends randomly, they will be given a position from 1 to 5.
However, an array index always starts from 0. Here, we have 5 names, hence the index begins at zero. And the 5 elements will be at positions, 0,1,2,3,4. The last array index being 4.
Thus, If we have an array of 10 elements, then the elements to be referred to will be 0-9. Here, the length of array will be 10.
Again, Arrays can be of any data type as far as the values belong to a single type.
For example: Integer array of 6 elements for storing the price of 6 varieties of apple.
int apple[6];
23 45 33 65 76 77
apple[0] apple[1] apple[2] apple[3] apple[4] apple[5]
Name of all the elements is the same i.e. ‘apple’ but the reference index is changing from 0 to 5.
Recent Post
Adaptive Learning: AI based Personalized
Teacher Intelligence Vs AI- Will AI be able to replace teachers
WordPress.org vs WordPress.com
Types of websites and their purposes
Subscribe to our newsletter for courses and tutorial updates.