Now that you know how to take inputs from users, lets understand what Data-Types are, as they determine the kind of input and output out program can handle.
What are Data Types ?
A data type or simply type is a classification, identifying one of various types of data, such as real-valued, integer or character.
- It 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.
The basic data types in c are:
- Int
- Float
- Char
A complete list of data types is given below
Keyword | Variable Type | Range |
---|---|---|
char | Character (or string) | -128 to 127 |
int | Integer | -32,768 to 32,767 |
short 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 floating point (accurate to 7 digits) | ±3.4 × 10-38 to ±3.4 × 1038 |
double | Double-precision floating point (accurate to 15 digits) | ±1.7 × 10-308 to ±1.7 × 10308 |
What are Variables and how are they related to data types?
As the compiler needs to know what type of data is to be stored (different data types are stored differently as different operations can be performed based on the data type) we assign a data type to each variable.
The syntax to create variables is variable name followed by one or more variables, separated by comma. You can also initialize each variable in the same statement. Also as variables are declared from left to right you can use the value of the variable on the left to assign current variables' value.
Example: int a = 9, b = 2*a;
this way a=9 and b=18
Lets understand each data type in detail.
- Understanding integer data type.
- Understanding float data type.
- Understanding character data type.
No comments:
Post a Comment