0% found this document useful (0 votes)
2 views

C Data Types

The document provides an overview of data types in the C programming language, explaining the necessity of specifying a data type for variables. It details basic data types such as int, float, double, and char, along with their sizes and descriptions. Additionally, it introduces format specifiers used in the printf() function to display these data types.

Uploaded by

yash gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C Data Types

The document provides an overview of data types in the C programming language, explaining the necessity of specifying a data type for variables. It details basic data types such as int, float, double, and char, along with their sizes and descriptions. Additionally, it introduces format specifiers used in the printf() function to display these data types.

Uploaded by

yash gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

9/28/22, 8:15 PM C Data Types

 Tutorials  References  Exercises  Menu  Log in

Pro Get Certified Free Website


Dark mode
Dark code
  HTML CSS JAVASCRIPT SQL PYTHON   

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

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

int 2 or 4 bytes Stores whole numbers, without decimals

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

char 1 byte Stores a single character/letter/number, or ASCII values

https://www.w3schools.com/c/c_data_types.php 2/8
9/28/22, 8:15 PM C Data Types

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 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:

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 »

Start the Exercise

❮ 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

Master Basic &


Advanced Concepts in
Machine & Deep Open

Learning with IIM


IIM Kashipur | TimesPro Kashipur

Report Error Spaces Pro Buy Certificate

Top Tutorials Top References


HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference

https://www.w3schools.com/c/c_data_types.php 7/8
9/28/22, 8:15 PM C Data Types

C++ Tutorial Angular Reference


jQuery Tutorial jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

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.

Copyright 1999-2022 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by W3.CSS.

https://www.w3schools.com/c/c_data_types.php 8/8

You might also like