Data Types in C

Assume that we are going to use our age in the program.

To store and access age in the program, it's mandatory to define the data type of age first.

Let's choose the data type for age.




How to select the data type for age?

We always represent our age using a whole number or an integer. Say 20, 25. We will not use a floating number to represent our age. Like 20.3 years’ old. So, we should use integer data type for age.

similarly to represent weight, we always represent our weight using floating number. Example 52.3 kg, 70.5 kg etc.

So we should use datatype float for weight.

We should define the data type of a variable (age, weight) before assigning a value to it.




Major data types in C

Data Type

Description

Example

Size

int

To store an integer value

-5, -1,  0,  4

4 bytes

float

To store a floating point number
or number with fractional parts

10.3, 13.56, -2.45, 1.414

4 bytes

double

Same as float but bigger space to store number

123456.34534, -234345345.244466 etc

8 bytes

char

To store a single character

'a', 'b', 'c', '*', '#'

1 byte

void

It's an incomplete datatype.
Mainly used in functions.
We will discuss about it in later lessons

void fun() (i.e) fun() will not return anything
int main(void) (i.e) main will not take argument

1 byte