Q41)Explain datatypes used in “C”.
ans:-
Data type:-
When we write program we use different variable. Before we use them in our program we declare them with their data format to be used in memory. This format is called 'data type'.
Following are the types.There are two types of data types.
ans:-
Data type:-
When we write program we use different variable. Before we use them in our program we declare them with their data format to be used in memory. This format is called 'data type'.
Following are the types.There are two types of data types.
a) Basic
data type (Primary data type)
b) Derived data type(Secondary data type)
mostly called "Qualifier"
Let's
have look in detail about primary data types.
a) Basic data type:- Under this category we have four
types. They are int,float,char and double.Let's know about them.
a.1) int:-
It's a basic data type; we can use only integer type
of value by declaring variable with this. e.g
int sum;
This
declaration declares sum as integer type of variable. We can use or input
only integer type of value and under some range. We can not use other values
like fractional or exponential. And if we used then, the computer truncates the
fractional part. eg. int sum=3.4;
Here, we used int
data type but assigned fractional value (3.4); So computer stores only 3 instead
of 3.4. It occupies 2 bytes in memory and working range is -32768 to +32767.
a.2) float:-
Suppose, we want to use fractional
numbers; then we use float data type. This type supports numbers with decimal
digits(after dot) for a variable. Unlike integer (int ), it does not truncate
the fractional part and whole part is stored in memory.
float pi=4.67;
float a=6;
We have
taken simple examples. In first. the computer stores 4.67 in memory. Where as
in second we can see that number is integer but it has been declared as float,
in this case computer automatically converts the integer into float by putting
dot and zeros. i.e computer takes 6.00. In memory computer occupies 4 bytes for
this and can store up to or in range 3.4e-38 to 3.4e+38;good range it has to
work with.
a.3) Char:-
Char stands for a single character or sequence of many characters. We use this
data type if we want to use one character or a set (called string) to be
inputted. To be clear, let's have an example,
syntax goes like,
data type variable/s;
char a,b;
here, a and b are character
type of variables and can store one character. If we want to store one
character as a constant then we can assign like,
char
a='n';
here, a is character type of
variable and is storing 'n';
But
if we want to store more than one character or input then we can use,
char a[10];
here, we can enter a
string having maximum ten characters;we can also enter just one character. This
concept is called arrayed characters. In the case of constant,we use
char
a[10]="text";
String "text" is stored in
variable 'a' and it can store maximum 10 characters.
a.4) Double:-
This data type is used for exponential values and for more
accuracy of digits.It's working range is more than others. so if we want to use
long numbers of any type and high accuracy then...? for example,
data type variable;
double ab;
'ab' is a variable of double type. It can
store exponential values (3x104). It ca n be written as 3e+4 or 3E+4. If
power is in negative form then it can be in 3e-4 or 3E-4. It has one advantage
over others that it can be used in place of others easily.