C Data Types
C Data Types
C Data Types
❮ Previous Next ❯
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)
https://www.w3schools.com/c/c_data_types.php 1/8
9/28/22, 8:15 PM C Data Types
// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);
Try it Yourself »
float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 7
decimal digits
double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15
decimal digits
https://www.w3schools.com/c/c_data_types.php 2/8
9/28/22, 8:15 PM C Data Types
%d or %i int Try it »
%f float 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
Exercise:
Add the correct data type for the following variables:
https://www.w3schools.com/c/c_data_types.php 3/8
9/28/22, 8:15 PM C Data Types
myNum = 5;
myFloatNum = 5.99;
myLetter = 'D';
Submit Answer »
❮ Previous Next ❯
ADVERTISEMENT
NEW
https://www.w3schools.com/c/c_data_types.php 4/8
9/28/22, 8:15 PM C Data Types
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
a course today!
https://www.w3schools.com/c/c_data_types.php 5/8
9/28/22, 8:15 PM C Data Types
school
w3 s
2
CE
02
TI 2
R
FI .
ED
Get started
CODE GAME
Play Game
ADVERTISEMENT
https://www.w3schools.com/c/c_data_types.php 6/8
9/28/22, 8:15 PM C Data Types
ADVERTISEMENT
https://www.w3schools.com/c/c_data_types.php 7/8
9/28/22, 8:15 PM C Data Types
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are
constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our
terms of use, cookie and privacy policy.
https://www.w3schools.com/c/c_data_types.php 8/8