Data types in C-Programming refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.
In a c programming language, data types are classified as follows…
The primary data types in C-programming language are the basic datatypes. All the primary datatypes are already defined in the system. Primary data types are also called Built-In datatypes. The following are the primary datatypes in a c programming language.
An integer datatype is a set of whole numbers. Every integer value does not have a decimal value. We use the keyword “int” to represent integer datatype in c. We use the keyword int to declare the variables and to specify the return type of a function. The integer data type is used with different type modifiers like short, long, signed, and unsigned. The following table provides complete details about integer datatype.
Type | Storage size | Value Range |
---|---|---|
char | 1 byte | -128 to 127 or 0 to 255 |
unsigned char | 1 byte | 0 to 255 |
signed char | 1 byte | -128 to 127 |
int | 2 or 4 bytes | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 |
unsigned int | 2 or 4 bytes | 0 to 65,535 or 0 to 4,294,967,295 |
short | 2 bytes | -32,768 to 32,767 |
unsigned short | 2 bytes | 0 to 65,535 |
long | 4 bytes | -2,147,483,648 to 2,147,483,647 |
unsigned long | 4 bytes | 0 to 4,294,967,295 |
To get the exact size of a type or a variable on a particular platform, you can use the size of the operator. The expression size of (type) yields the storage size of the object or type in bytes. Given below is an example to get the size of the int type on any machine −
#include <stdio.h> #include <conio.h> int main() { clrscr(); printf("The Storage size for int : %d \n", sizeof(int)); getch(); }
When you compile and execute the above program, it produces the following result on Linux −
The Storage size for int : 4
The floating point data type consists of 2 types to understand it sees the table given below.
Type | Storage size | Value Range | Precision |
---|---|---|---|
float | 4 byte | 1.2E-38 to 3.4E+38 | 6 decimal places |
double | 8 byte | 2.3E-308 to 1.7E+308 | 15 decimal places |
long double | 10 byte | 3.4E-4932 to 1.1E+4932 | 19 decimal places |
Float data has two types;
Example:
#include <stdio.h> #include <Conio.h> int main() { clrscr(); printf(" The Storage size for float : %d \n", sizeof(float)); printf("The Minimum float positive value: %E\n", FLT_MIN ); printf(" The Maximum float positive value: %E\n", FLT_MAX ); printf(" The Precision value: %d\n", FLT_DIG ); getch(); }
When you compile and execute the above program, it produces the following result on Linux −
The Storage size for float : 4 The Minimum float positive value: 1.175494E-38 The Maximum float positive value: 3.402823E+38 The Precision value: 6
char test = 'h';
Here, the test is a character variable. The value of the test is ‘h’.
The size of the character variable is 1 byte.
#include <stdio.h>
typedef struct {
void* fn;
void* param;
} event;
void print()
{
printf("Hello\n");
}
int main()
{
event e;
e.fn = print;
((void(*)())e.fn)();
return 0;
An enumerated data type in c is a user-defined data type that consists of integer constants and each integer constant is given a name. The keyword “enum” is used to define enumerated datatype.
Derived data types in c are user-defined data types. The derived datatypes are also called user-defined datatypes or secondary datatypes. In a c programming language, the derived datatypes are created using the following concepts…