Data Types and Keywords
From Wikiversity
[edit] C Data Types
In C, there is a concept called "datatypes". Data types indicate the type of data a variable can hold. When a variable is defined, a memory location will be assigned to the newly defined variable and it will also define the type of data that memory location will hold. C has following data types
- int - an integer; reflects size of integers on host machine
- float - single-precision floating point
- double - double-precision floating point
- char - character, a single byte
In addition to basic data types C also defines certain qualifiers to these data types. Qualifiers are used to make variable declaration more specific to variable uses. Qualifiers available in the C language are:
- short (applied to integers)
- long (applied to integers)
- signed (applied to char, or any integer)
- unsigned (applied to char, or any integer)
With application of these qualifiers basic data types can be flavoured in many ways as given in the table below. Note that the values given are acceptable minimum magnitudes defined by the C Standard - each implementation will define values greater or equal in magnitude.
| Data Type | Bits | Range Begin | Range End |
| char | 8 | -127 | 127 |
| unsigned char | 8 | 0 | 255 |
| short int | 16 | -32767 | +32767 |
| unsigned short | 16 | 0 | 65,535 |
| int | 16 | -32,767 | 32,767 |
| unsigned int | 16 | 0 | 65,535 |
| long int | 32 | -2,147,483,647 | 2,147,483,647 |
| unsigned long int | 32 | 0 | 4,294,967,295 |
| float | 32 | 1e-37 | 1e+37 |
| double | 32 | 1e-37 | 1e+37 |
| long double | 32 | 1e-37 | 1e+37 |
[edit] Examples
[edit] Exercises
- What data type(s) could you use if you were creating a program that stored monetary sums (Dollars, Euros, etc.)?
- What data type could you use to store if you wanted someone to type their name into your program?
- What data type(s) could you need if you wanted to count from 0 to 100?
| Project: Topic:C |
| Previous: Introduction to C — Data Types and Keywords — Next: Type Qualifiers |