Discuss about the various data types in "C". (MAY 2009)
The four basic data types are
a. INTEGER
These are whole numbers, both positive and negative. Unsigned integers (positive values only) are supported. In addition, there are short and long integers.
The keyword used to define integers is, int An example of an integer value is 32. An example of declaring an integer variable called sum is, int sum;sum = 20;
b. FLOATING POINT
These are numbers which contain fractional parts, both positive and negative. The keyword used to define float variables is,float
An example of a float value is 34.12. An example of declaring a float variable called money is,
float money;
money = 0.12;
c. DOUBLE
These are exponentional numbers, both positive and negative. The keyword used to define double variables is, double An example of a double value is 3.0E2. An example of declaring a double variable called big is, double big; big = 312E+7;
d. CHARACTER
These are single characters. The keyword used to define character variables is, char
An example of a character value is the letter A. An example of declaring a character variable called letter is, char letter; letter = „A‟;
Note the assignment of the character A to the variable letter is done by enclosing the value in single quotes.
#include < stdio.h >
main()
{
int sum;
float money; char letter; double pi;
sum = 10; /* assign integer value */ money = 2.21; /* assign float value */ letter = „A‟; /* assign character value */ pi = 2.01E6; /* assign a double value */ printf(“value of sum = %d\n”, sum );
printf(“value of money = %f\n”, money ); printf(“value of letter = %c\n”, letter ); printf(“value of pi = %e\n”, pi );
}
Sample program output
value of sum = 10
value of money = 2.210000 value of letter = A
value of pi = 2.010000e+06
The four basic data types are
a. INTEGER
These are whole numbers, both positive and negative. Unsigned integers (positive values only) are supported. In addition, there are short and long integers.
The keyword used to define integers is, int An example of an integer value is 32. An example of declaring an integer variable called sum is, int sum;sum = 20;
b. FLOATING POINT
These are numbers which contain fractional parts, both positive and negative. The keyword used to define float variables is,float
An example of a float value is 34.12. An example of declaring a float variable called money is,
float money;
money = 0.12;
c. DOUBLE
These are exponentional numbers, both positive and negative. The keyword used to define double variables is, double An example of a double value is 3.0E2. An example of declaring a double variable called big is, double big; big = 312E+7;
d. CHARACTER
These are single characters. The keyword used to define character variables is, char
An example of a character value is the letter A. An example of declaring a character variable called letter is, char letter; letter = „A‟;
Note the assignment of the character A to the variable letter is done by enclosing the value in single quotes.
#include < stdio.h >
main()
{
int sum;
float money; char letter; double pi;
sum = 10; /* assign integer value */ money = 2.21; /* assign float value */ letter = „A‟; /* assign character value */ pi = 2.01E6; /* assign a double value */ printf(“value of sum = %d\n”, sum );
printf(“value of money = %f\n”, money ); printf(“value of letter = %c\n”, letter ); printf(“value of pi = %e\n”, pi );
}
Sample program output
value of sum = 10
value of money = 2.210000 value of letter = A
value of pi = 2.010000e+06
No comments:
Post a Comment