Friday, July 18, 2014

Variables and Data Types Introduction

In computer science and computer programming, a data type or simply type is a classification identifying one of various types of data, such as Real, Integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.

Variables:

Variables are placeholders used to store values; they have names and data types. The data type of a variable determines how the bits representing those values are stored in the computer's memory. When you declare a variable, you can also supply a data type for it. All variables have a data type that determines what kind of data they can store.

Or in other words, in computer science we need something for holding data and variables are the facility for doing that.

Data Types:

To solve any equation, we need to relate variables to the kind of values they can take and data type is the name being used in computer science for this purpose.

A data type in a programming language is a set of data with values having predefined characteristics.

Computer memory is all filled with zeros and ones. If we have a problem and wanted to code it, it's very difficult to provide the solution in terms of zeros and ones. To help users, programming languages and compilers are providing the facility of data types.

A data type reduces the coding effort. Basically, at the top level, there are two types of data types:
  • System Defined Data Types (Primitive Data Types) 
  • User Defined Data Types

System Defined Data Types (Primitive Data Types):

Data types which are defined by system are called primitive data types. the primitive data types which are provided by many programming languages are: boolean, byte, short, int, float, double, etc... The number of bits allocated for each primitive data type depend on the programming languages, compiler and operating system. For the same primitive data type, different languages may use different sizes. Depending on the size of the data types the total available values (domain) will also changes.

User Defined Data Types:

If the system defined data types are not enough then most programming languages allow the users to define their own data types called user defined data type. Good example of user defined data types are : structures in C/C++ and classes in JAVA.

0 comments:

Post a Comment