C Data Types
C Data Types
In C programming, data types are declarations for variables. This determines the type
and size of data associated with variables. For example,
1. int myVar;
Here, myVar is a variable of int (integer) type. The size of int is 4 bytes.
Basic types
Here's a table containing commonly used types in C programming for quick access.
char 1 %c
float 4 %f
double 8 %lf
short
int 2 usually %hd
int
Integers are whole numbers that can have both zero, positive and negative values but
no decimal values. For example, 0, -5, 10
We can use int for declaring an integer variable.
1. int id;
Here, id is a variable of type integer.
char
Keyword char is used for declaring character type variables. For example,
1. char test = 'h';
void
void is an incomplete type. It means "nothing" or "no type". You can think of void
as absent.
For example, if a function is not returning anything, its return type should be void.
Note that, you cannot create variables of void type.
You can always check the size of a variable using the sizeof() operator.
1. #include <stdio.h>
2. int main() {
3. short a;
4. long b;
5. long long c;
6. long double d;
7.
8. printf("size of short = %d bytes\n", sizeof(a));
9. printf("size of long = %d bytes\n", sizeof(b));
10. printf("size of long long = %d bytes\n", sizeof(c));
11. printf("size of long double= %d bytes\n", sizeof(d));
12. return 0;
13. }
bool Type
Enumerated type
Complex types