1) Numeric Data Types
Keyword Variable Type Range
char Character (or string) -128 to 127
int Integer -32,768 to 32,767
short Short integer -32,768 to 32,767
short int Short integer -32,768 to 32,767
long Long integer -2,147,483,648 to 2,147,483,647
unsigned char Unsigned character 0 to 255
unsigned int Unsigned integer 0 to 65,535
unsigned short Unsigned short integer 0 to 65,535
unsigned long Unsigned long integer 0 to 4,294,967,295
float Single-precision +/-3.4E10^38 to +/-3.4E10^38
floating-point
(accurate to 7 digits)
double Double-precision +/-1.7E10^308 to +/-1.7E10^308
floating-point
(accurate to 15 digits)
C has really only four types of variables: |
|
1)enum
#include <stdio.h>
enum months {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };
int main()
{
enum months month;
const char *monthName[] = { "", "January", "February", "March",
"April", "May", "June", "July", "August", "September", "October",
"November", "December" };
for ( month = JAN; month <= DEC; month++ ) {
printf( "%2d%11s\n", month, monthName[ month ] );
}
return 0;
}
3) Union
| |
|
#include <stdio.h>
union marks
{
float percent;
char grade;
};
int main ( )
{
union marks student1;
student1.percent = 98.5;
printf( "Marks are %f address is %16lu\n", student1.percent, &student1.percent);
student1.grade = 'A';
printf( "Grade is %c address is %16lu\n", student1.grade, &student1.grade);
}
4) Comparing the equality operator (==) with the '=' assignment operator.
| ||||||||||||||||
|
5) Register variable
Register variable is for faster access. |
Register variable cannot be global variables. |
#include <stdio.h>
main()
{
register int i = 0;
for( i=0;i<2;i++)
{
printf("value of i is %d\n",i);
}
}
6) Type conversion
- Type conversion occurs when the expression has data of mixed data types.
- In type conversion, the data type is promoted from lower to higher.
- The hierarchy of data types: double, float, long, int, short, char.