1. Introduction
A data type in C specifies the kind of value a variable can hold, how much memory it occupies, and what operations can be performed on it. C provides a small set of built-in (primitive) data types along with type modifiers that let programmers fine-tune size and range.
Cricket analogy: Declaring a player's role as 'bowler' vs 'batsman' determines what actions (bowling figures vs batting average) get tracked and how much scorecard space is reserved — just like a C data type determines memory size and allowed operations.
Choosing the correct data type affects memory usage, precision, and correctness of arithmetic, which is why data types form the foundation for nearly every other C topic, from arrays to structures.
Cricket analogy: Recording a batsman's strike rate as an int truncates decimals like 133.33 down to 133, just as choosing the wrong data type in C silently loses precision that matters for later analysis.
2. Syntax
int variableName;
float variableName;
double variableName;
char variableName;
short int / long int / long long int
unsigned int / signed int3. Explanation
C's fundamental data types fall into a few categories: integer types (char, short, int, long, long long — each available in signed and unsigned form), floating-point types (float, double, long double) for real numbers with fractional parts, and void, which represents 'no value' and is used for functions that return nothing or generic pointers.
Cricket analogy: A scorecard uses whole-number types (int) for runs and wickets, but a decimal type (double) for the required run rate like 8.45, and a 'void' placeholder for an abandoned match with no result at all.
Type modifiers — signed, unsigned, short, and long — adjust the size and range of a base type. On a typical 32-bit/64-bit system (LP64), int is commonly 4 bytes (range approximately -2,147,483,648 to 2,147,483,647), char is 1 byte, float is 4 bytes, and double is 8 bytes, though exact sizes are implementation-defined and should be verified with sizeof(). The correct printf/scanf format specifier must match the type: %d for int, %f for float, %lf for double (in scanf), %c for char, and %ld for long.
Cricket analogy: A 'signed' run tally can go negative (like a bowler's economy differential of -2), while an 'unsigned' wicket count never goes below zero — and using %d to print a long total like a season's aggregate runs (over 2 billion in T20 leagues) would truncate, just as mismatching format specifiers corrupts output.
Common mistake: using %f to scanf a double variable. printf treats float and double the same due to default argument promotion, but scanf requires %lf for double and %f for float — mismatching these causes undefined behavior.
4. Example
#include <stdio.h>
int main(void) {
int i = 42;
float f = 3.14f;
double d = 3.14159265358979;
char c = 'Z';
unsigned int u = 4000000000u;
printf("int: %d, size = %zu bytes\n", i, sizeof(i));
printf("float: %.2f, size = %zu bytes\n", f, sizeof(f));
printf("double: %.5f, size = %zu bytes\n", d, sizeof(d));
printf("char: %c, size = %zu bytes\n", c, sizeof(c));
printf("unsigned int: %u, size = %zu bytes\n", u, sizeof(u));
return 0;
}5. Output
int: 42, size = 4 bytes
float: 3.14, size = 4 bytes
double: 3.14159, size = 8 bytes
char: Z, size = 1 bytes
unsigned int: 4000000000, size = 4 bytes6. Key Takeaways
- C's basic types are int, float, double, char, and void.
- Modifiers signed/unsigned/short/long adjust size and range of base types.
- Exact type sizes are compiler/platform-defined; always confirm with sizeof().
- Use matching format specifiers: %d (int), %f (float print), %lf (double scanf), %c (char).
- unsigned types can never hold negative values and wrap around on underflow/overflow.
- double offers roughly twice the precision of float and is preferred for scientific calculations.
Practice what you learned
1. Which format specifier should be used with scanf() to read a double value?
2. What is the typical size of an int on most modern 32-bit and 64-bit systems?
3. Which data type is used in C to represent the absence of a value or a generic pointer type?
4. Which operator should be used to determine the exact byte size of a data type on a given system?
5. What happens when an unsigned int variable is assigned a negative value like -1?
Was this page helpful?
You May Also Like
Variables in C
Learn C variables: declaration, initialization, naming rules, scope, and exam-ready examples with compilable code.
typedef in C
Understand C's typedef keyword to create readable type aliases for structs, pointers, and primitive types.
Constants in C
Understand C constants: literals, #define, const keyword, enumeration constants, and how to use each correctly.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics