We have seen that
variables are placeholders for data. When we say data, it can be a integral
numbers like 3,5 or it can be a real number like 2.6 , 1.8.
numbers like 3,5 or it can be a real number like 2.6 , 1.8.
In computer science,
we define different types of data which we can store in memory location.
A data type in a programming language is set of data with predefined values. Examples include,
integers, floating point, characters, Strings etc.
A data type in a programming language is set of data with predefined values. Examples include,
integers, floating point, characters, Strings etc.
Even though
ultimatly everything in memory stored in terms of zeros and ones, it is not
practical
for us to code interms of zeros and ones. So to help users with programming compilers provide
programmers the data types, which are in readable data which we use in day today transactions.
for us to code interms of zeros and ones. So to help users with programming compilers provide
programmers the data types, which are in readable data which we use in day today transactions.
The data types are
categorized based on the representation in memory or the size it occupies in
memory. For example, integer takes 4 bytes ( depends on the compiler, some may take 2 bytes),
float takes 4 bytes, a character takes 1 byte.
memory. For example, integer takes 4 bytes ( depends on the compiler, some may take 2 bytes),
float takes 4 bytes, a character takes 1 byte.
There are two types
of data types.
- System defined data types
- User-defined data types
System defined data types
These are primitive
data types which are defined by the system. Many programming languages
provide these basic primitive data types int, float, char, bool. Double, long etc. The size of the each
data type depends on the compiler, operating system. Depending on the size of the data type,
the total available values in that specific data types will change.
provide these basic primitive data types int, float, char, bool. Double, long etc. The size of the each
data type depends on the compiler, operating system. Depending on the size of the data type,
the total available values in that specific data types will change.
For example, int may
take 2 or 4 bytes, if it takes 2 bytes (16 bits) then the total possible values
are -32,768 (-215) to 32,767 (+215 -1 ). If it tales 4 bytes ( 32 bits ) then the range of values
are -231to +231-1.
are -32,768 (-215) to 32,767 (+215 -1 ). If it tales 4 bytes ( 32 bits ) then the range of values
are -231to +231-1.
User defined data types
Most of the
programming languages allow user to define their own data types with the help
of
primitive data types. Example for user defined data types are structures and classes.
primitive data types. Example for user defined data types are structures and classes.
Ex : Struct
NewUserDefinedType {
int data1;
char data 2;
……
};
Comments
Post a Comment