C Data Types
In c we declare a variable with a data type to store the type of data.
Here are some data types
- Integer Types - int, short, long, unsigned int, unsigned short, unsigned long
- Floating-Point Types - float, double, long double
- Character Type - char
Integer Types
A varable which is declared by a integer data type then the value only holds integer values.
There are different types of integer to allocate fixed memory to the variable base on the size it provides to hold a value.
There are different types of integer to allocate fixed memory to the variable base on the size it provides to hold a value.
Type
Size (bytes)
Range
int
4
-2,147,483,648 to 2,147,483,647
short
2
-32,768 to 32,767
long
4 or 8 (platform-dependent)
-2,147,483,648 to 2,147,483,647 (32-bit) or -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (64-bit)
unsigned int
4
0 to 4,294,967,295
unsigned short
2
0 to 65,535
unsigned long
4 or 8 (platform-dependent)
0 to 4,294,967,295 (32-bit) or 0 to 18,446,744,073,709,551,615 (64-bit)
Example
#include <stdio.h>
int main() {
int integerVar = 42;
short shortVar = 32767;
long longVar = 1234567890;
unsigned int unsignedIntVar = 100;
unsigned short unsignedShortVar = 65535;
unsigned long unsignedLongVar = 4294967295;
printf("Integer: %d\n", integerVar);
printf("Short: %d\n", shortVar);
printf("Long: %ld\n", longVar);
printf("Unsigned Integer: %u\n", unsignedIntVar);
printf("Unsigned Short: %u\n", unsignedShortVar);
printf("Unsigned Long: %u\n", unsignedLongVar);
return 0;
}
Floating-point Types
A varable which is declared by a Float data type then the value only holds decimal values.
There are different types of float to allocate fixed memory to the variable base on the size it provides to hold a number of decimal values.
There are different types of float to allocate fixed memory to the variable base on the size it provides to hold a number of decimal values.
Type
Size (bytes)
Precision
Range
float
4
6 decimal places
±1.17549e-38 to ±3.40282e+38
double
8
15 decimal places
±2.22507e-308 to ±1.79769e+308
long double
Platform-dependent
Extended precision
Platform-dependent
Example
#include <stdio.h>
int main() {
float price = 29.99;
double pi = 3.141592653589793;
long double largeNumber = 12345678901234567890.123456789;
printf("Price: $%.2f\n", price);
printf("Value of Pi: %.10f\n", pi);
printf("Large Number: %.15Lf\n", largeNumber);
return 0;
}
Character Type
char is the only Character type in c.
It has always a size of 1 byte.
Has a Range of -128 to 127 (signed) or 0 to 255 (unsigned)
It has always a size of 1 byte.
Has a Range of -128 to 127 (signed) or 0 to 255 (unsigned)
Example
#include <stdio.h>
int main() {
char charVar = 'A';
printf("Character: %c\n", charVar);
return 0;
}
Quick Recap
Topics Covered
Data Types in C
Integer Data Types
Float Data Types
Character Data Types
Practice With Examples in Compilers
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compile
Example 1
Example 1
Example 2
Example 3
Example 4
Example 5