Data types of Variables

Data types specify the type of data getting stored in the variable. They restrict other types of data to be stored in the variable. In this tutorial we will discuss about some basic data types and their implementation.

For Numbers

The basic data types which we commonly used to store numbers are given below.

  • int - stores integer value.
  • float - it stores decimal values.
  • double - it also stores decimal values but its precision is double than float.

Char Data Type

Char data type is used to store any single character in a variable.

Boolean Data Type

Boolean data type stores only true / False. For using booleans in C, you have to import header file. It return 1 if true and 0 if false.

Booleans can store:

  1. true / false
  2. 1 / 0
  3. Yes / No

String Data Type

String data type is use to store sequence of characters/text/anything inside double quotation marks.

We will learn about string data type in detail in later tutorial.

Format Specifiers

Format specifiers in C are used with functions like printf and scanf to specify the expected format of the data to be printed or read.

Data TypeFormat specifier
int%d
float%f
double%lf
char%c
string%s

Size of Data Types

Size of variable depends upon the data type of variable.

Data TypeSize
char1 byte
bool1 byte
int2 or 4 bytes
float4 bytes
double8 bytes

Note: It is not important to remember the size of all data types.

sizeof() operator

We can find the size of any data type or variable using sizeof() operator. Let's see an example.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which data type is used to store decimal numbers?

10 XP~2 min
Exercise 2 of 2Medium

What is the typical size of an int data type?

15 XP~3 min