Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C Data Types


Data Types

As explained in the Variables chapter, a variable in C must be a specified data type, and you must use a format specifier inside the printf() function to display it:

Example

// Create variables
int myNum = 5;             // Integer (whole number)
float myFloatNum = 5.99;   // Floating point number
char myLetter = 'D';       // Character

// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);
Try it Yourself »

Basic Data Types

The data type specifies the size and type of information the variable will store.

In this tutorial, we will focus on the most basic ones:

Data Type Size Description Example
int 2 or 4 bytes Stores whole numbers, without decimals 1
float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits 1.99
double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits 1.99
char 1 byte Stores a single character/letter/number, or ASCII values 'A'

Basic Format Specifiers

There are different format specifiers for each data type. Here are some of them:

Format Specifier Data Type Try it
%d or %i int Try it »
%f or %F float Try it »
%lf double Try it »
%c char Try it »
%s Used for strings (text), which you will learn more about in a later chapter Try it »

C Exercises

Test Yourself With Exercises

Exercise:

Add the correct data type for the following variables:

 myNum = 5;
 myFloatNum = 5.99;
 myLetter = 'D';

Start the Exercise