In the C programming language, there are three main categories of data types: primary, derived, and user-defined data types. In this article, we will focus only on the primary data types, also known as fundamental data types.
Primary Data Type
Primary data type are pre-defined, meaning they already exist in C programming language. Thes data type can be classify into types used for variable values and types used for constant values.
Data type |
Memory(byte) |
Precision |
Specifier |
|---|---|---|---|
| char | 1 | none | %c |
| int | 4 | none | %d |
| folat | 4 | 6 |
%f |
| double | 8 | 15 | %lf |
Data Types For Variable Values:
Syntax of variable primary data type :
type name = value ;
1 character and integer :
Primary data types character and integer can be written in two formats:
unsigned → to represent non-negative values, which can be only zero or postive numbers only.
signed→to represent both positive and negative values, including zero.
important notes:
- By default, all data types are signed, which means you do not need to write signed explicitly.
- To adjust the size or precision of a data type, you can use the long and short modifiers.
1.1) charachter :(Alpha Numerical) :
The char data type is used to store single characters.
Internally, each charcter is stored as integer value corresponding to its ASCII code (for example, A = 65, B = 66, etc.).
signed char : can store values from -128 to 127.
signed int : can store values from -2147483648 to 2147483647 (on a 4-byte system).
unsigned int : The unsigned int data type is used to store non-negative integer values only.
Range: from 0 to 4294967295 (on a 4-byte system).
-Declaration first, then assignment:
unsigned int name ;
name = value ;
example :
1.3) long int :
The long int data type is similar to int, but it can store larger integer values.
The main difference is in the size and syntax.
signed long long int : can store values from -9223372036854775808 to 9223372036854775807 .
- Declaration first, then assignment:
long long name ;
name = value ;
example :
Unsigned long long int → can store values from 0 to 18,446,744,073,709,551,615.
unsigend long long name = value ;
- Declaration first, then assignment:
unsigned long long name ;
naname = value ;
example :
2 float and double :
2.1) float :
This is the second part of the variable data types. It is mainly used to store floating-point numbers.
The float data type can store numbers with a range from 1.175494E−38 to 3.402823E+38, and it occupies 4 bytes in RAM.
2.2) double :
if we need to more precision we use this type because it have precision value up to 15 and his range is 2.225074E-308 to 1.797693E+308 and take 8 byte on RAM .
or
double name ;
name = value ;
2.3) long double :
precision ois 18 number and range of 3.4E-4932 to 1.1E+4932 but it take 12 byte on RAM .
long double name = value ;
or
long name ;
name = value ;
example :
Data Types For Constant Values:
In C languages constants are the fixed values (not change) that never change during the execution of a program . It can have any data type , and there are two ways to define constant which is : #define preprocessor and const keyword .
1) #define :
This directive does not store into RAM but it used to replace every insurance of label with text . and this text does not change at all .
#define label text
example :
2) const :
This keyword is used to create constant values . It work with all different primary data type , but it take as much space on mermory as any other variable .
const type name = value ;
example :
