Nearby lessons

12 of 72

C - Data Types

Data Types is one of the foundational topics in C programming. This lesson explains The Basic Data Types — Each One in Its Own Program, Program 1: int (whole numbers) and Program 2: float (decimal numbers) with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

The Basic Data Types — Each One in Its Own Program

A data type tells C what kind of value a variable will store. Let us see each of the four basic types running on its own.

Data typeStoresSize (approx)Example
intWhole numbers (integers)2 or 4 bytesint age = 20;
floatNumbers with decimal points4 bytesfloat pi = 3.14;
doubleDecimal numbers with more precision8 bytesdouble price = 99.99;
charOne single character1 bytechar grade = 'A';
In simple words: the data type tells the machine how to treat your value — int for whole numbers, float/double for decimals, char for one single letter.

Program 1: int (whole numbers)

Example02
Loading editor…

Program 2: float (decimal numbers)

Example03
Loading editor…

Program 3: double (more precision)

Example04
Loading editor…

Program 4: char (one character)

Trainer's Note: Size trick: char is always 1 byte (holds one character). int is the standard whole number. Use float for simple decimals and double when you need very accurate decimals (like scientific calculations).
Example05
Loading editor…

Declaration and Initialization

Declaration tells C the type and name. Initialization gives a value at the time of declaration.

Example06
Loading editor…

Program: declaration styles in action

Example07
Loading editor…
📝 Key Takeaways
  • Tokens = keywords, identifiers, constants, operators, special symbols.
  • Constants never change; variables can hold different values.
  • Identifier rules: start with letter/underscore, no spaces/symbols, no keywords.
  • Basic data types: int, float, double, char — each with its own example program.
  • Declaration = type + name; initialization = giving a value.
  • sizeof tells the memory size of a type.

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.