0 ratings0% found this document useful (0 votes) 86 views15 pagesData Type in C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
417124, 10228M Data Types in C - GeekstorGasks
© CBasics CDataTypes COperators Cinputand Output CControlFlow Functions CArrays CStrin
Data Types in C
Each variable in C has an associated data type. It specifies the type of data that
the variable can store like integer, character, floating, double, etc. Each data
type requires different amounts of memory and has some specific operations
which can be performed over it. The data type is a collection of data with
values having fixed values, meaning as well as its characteristics.
The data types in C can be classified as follows:
Types Description
ae Primitive data types are the most basic data types that are
Primitive Data
used for representing simple values such as integers, float,
Types
ve characters, ete
User Defined
The user-defined data types are defined by the user himself,
Data Types
The data types that are derived from the primitive or built-in
Derived Types
datatypes are referred to as Derived Data Types.
DataTypes in C
o>
Primary Derived User Defined
We use cookies to ensure you have the best browsing experience on our website. By using our
Got it!
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! ans.417124, 10228M
Data Types in C - GeekstorGasks
Different data types also have different ranges up to which they can store
numbers. These ranges may vary from compiler to compiler. Below is a list of
ranges along with the memory requirement and format specifiers on the 32-bit
GCC compiler.
Data Type
short int
unsigned short
int
unsigned int
int
long int
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
hntps:inww-geokstorgeoks orgidata-types-in-)
Size
(bytes)
4
Range
-32,768 to 32,767
0 to 65,535,
0 to 4,294,967,295
-2,147,483,648 to
2,147,483,647
-2,147,483,648 to
Format
Specifier
%hd
Shu
%d
%ld
26417124, 10228M Data Types in C - GeekstorGasks
Data Type Size Range Format
(bytes) Specifier
unsigned long
int 4 0 to 4,294,967,295 lu
long long int 8 -(2463) to (2063)-1 %lld
unsigned tong 8 Oto satu
long int 18,446,744,073,709,551,615
signed char 1 -128 to 127 %c
unsigned char 1 0 to 255 %e
float 4 VF
1.2E-38 to 3.4E+38
double 8 MIF
1,7E-308 to 1.7E+308
tong double 16 LF
3.4E-4932 to 1.16+4932
Note: The long, short, signed and unsigned are datatype modifier that
can be used with some primitive data types to change the size or length
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! 3s417124, 10228M Data Types in C - GeekstorGasks
The following are some main primitive data types in C:
Integer Data Type
The integer datatype in C is used to store the integer numbers(any number
including positive, negative and zero without decimal part). Octal values,
hexadecimal values, and decimal values can be stored in int data type in C.
+ Range: -2,147,483,648 to 2,147,483,647
* Size: 4 bytes
+ Format Specifier: %d
Syntax of Integer
We use int keyword to declare the integer variable:
int var_nane;
The integer data type can also be used as
1. unsigned int: Unsigned int data type in C is used to store the data values
from zero to positive numbers but it can't store negative values like signed
int.
2. short int: Its lesser in size than the int by 2 bytes so can only store values
from -32,768 to 32,767.
3. long int: Larger version of the int datatype so can store values greater than
int.
4. unsigned short int: Similar in relationship with short int as unsigned int
with int.
Note: The size of an integer data type is compiler-dependent. We can use
sizeof operator to check the actual size of any data type.
Example of int
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! ans417124, 10228M Data Types in C - GeekstorGasks
// © program to print Integer data types.
include
int main()
{
// Integer value with positive data.
int a= 95
// integer value with negative data.
int b = -93
// U or u is Used for Unsigned int in C.
int ¢ = 89U;
// Lor 1 is used for long int in C.
long int d = 99998L;
printf ("Integer value with positive data: %d\n", a);
printf ("Integer value with negative data: %d\n", b);
printf ("Integer value with an unsigned int data: %u\n",
)5
printf ("Integer value with an long int data: %ld", d)5
return 0;
Output
Integer value with positive data: 9
Integer value with negative data: -9
Integer value with an unsigned int data: 89
Integer value with an long int data: 99998
Character Data Type
Character data type allows its variable to store only a single character. The size
of the character is 1 byte. It is the most basic data type in C. It stores a single
character and requires a single byte of memory in almost all compilers.
* Range: (-128 to 127) or (0 to 255)
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! 515417124, 10228M Data Types in C - GeekstorGasks
Syntax of char
The char keyword is used to declare the variable of character type:
char var_nane;
Example of char
c
// © program to print Integer data types.
include
int main()
{
char a= ‘a's
char c;
print#("Value of a: Xc\n", a)5
ats
printf ("Value of a after increment is: %c\n", a)j
//c is assigned ASCII values
// which corresponds to the
VI character ‘c*
I a-->97 b-->98 c-->99
// here ¢ will be printed
c= 995
printf("Value of ci %e", ¢);
return @;
Output
Value of
init
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoksoridata-ypes-i-c! ens417124, 10228M Data Types in C - GeekstorGasks
Value of c: ¢
Float Data Type
In C programming float data type is used to store floating-point values. Float in
Cis used to store decimal and exponential values. It is used to store decimal
numbers (numbers with floating point values) with single precision.
* Range: 1.2E-38 to 3.4£+38
* Size: 4 bytes
* Format Specifier: %f
Syntax of float
The float keyword is used to declare the variable as a floating point:
float var_name;
Example of Float
c
// © Program to demonstrate use
// of Floating types
include
int main()
{
float a = 9.0f;
float b = 2.5f;
11 2x109-4
float c = 2E-4#;
print#("%f\n", a)3
printf(“%f\n", b)5
printf("%F", ¢)5
return 0;
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! 78417124, 10228M Data Types in C - GeekstorGasks
Output
9. ee22ee
2, 5e0ee
@.e0e20e
Double Data Type
A Double data type in C is used to store decimal numbers (numbers with
floating point values) with double precision. It is used to define numeric values
which hold numbers with decimal values in C.
‘The double data type is basically a precision sort of data type that is capable of
holding 64 bits of decimal numbers or floating points. Since double has more
precision as compared to that float then it is much more obvious that it
occupies twice the memory occupied by the floating-point type. It can easily
accommodate about 16 to 17 digits after or before a decimal point.
+ Range: 1.7E-308 to 1.7E+308
* Size: 8 bytes
+ Format Specifier: %lf
Syntax of Double
The variable can be declared as double precision floating point using the
double keyword:
double var_nane;
Example of Double
c
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! ans417124, 10228M Data Types in C - GeekstorGasks
int main()
t
double a = 123123123.00;
double b = 12.293123;
double ¢ = 2312312312.123123;
print#("%1F\n", a);
printf("%1#\n", b);
printf("%1f", ¢);
return @;
Output
123123123, e2@@00
12,293123
2312312312, 123123
Void Data Type
The void data type in C is used to specify that no value is present. It does not.
provide a result value to its caller. It has no values and no operations. It is used
to represent nothing. Void is used in multiple ways as function return type,
function arguments as void, and pointers to void
Syntax:
// function return type void
void exit(int check);
// Function without any parameter can accept void.
int print (void);
// mewory allocation function which
// returns a pointer to void.
void *malloc (size_t size);
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! ons417124, 10228M Data Types in C - GeekstorGasks
Example of Void
c
// © program to demonstrate
// use of void pointers
include
int main()
{
int val = 30;
void* ptr = aval;
print#("%d", *(int*)ptr);
return @;
Output
3e
Size of Data Types in C
The size of the data types in C is dependent on the size of the architecture, so
we cannot define the universal size of the data types. For that, the C language
provides the sizeof() operator to check the size of the data types.
Example
c
// © Program to print size of
// different data type in
Hinclude
int main()
{
int size_of_int = sizeof(int);
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! 10115417124, 10228M Data Types in C - GeekstorGasks
print#("The size of int data type : %d\n", size_of_int);
print#("The size of char data type : %d\n",
size_of_char);
print#("The size of float data type : %d\n",
size_of float);
print#("The size of double data type : %d",
size_of_double);
return 9;
Output
The size of int data type : 4
The size of char data type : 1
The size of float data type : 4
The size of double data type : 8
To check your knowledge of data types in C, go through the Quiz on Data
Types.
Get 90% Course fee refund in just 90 Days! Also get 1:1 Mock Interview, Job
assistance and more additional benefits on selected courses. Take up the
Three 90 challenge today!
Here's a complete roadmap for you to become a developer: Learn DSA ->
Master Frontend/Backend/Full Stack -> Build Projects -> Keep Applying to
Jobs
And why go anywhere else when our DSA to Development: Coding Guide
helps you do this in a single program! Apply now to our DSA to Development
Program and our counsellors will connect with you for further guidance &
support.
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! ss417124, 10228M Data Types in C - GeekstorGasks
Last Updated : 28 Sep, 2023
Previous
Global Variables in C
Share your thoughts in the comments
Similar Reads
Difference between fundamental data
types and derived data types
C| Data Types | Question 1
C| Data Types | Question 4
C | Data Types | Question 6
C| Data Types | Question 8
eo GeeksforGeeks
Article Tags: Basics, C-Data Types, C Language
391
Next
Literals in C
How to Convert Data From SQL to C Data
Types?
C| Data Types | Question 2
C| Data Types | Question 5
C | Data Types| Question 7
C | Data Types | Question 9
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
hntps:nww-geokstorgeoks orgidata-types-in-)
rans417124, 10228M Data Types in C - GeekstorGasks
OG GeeksforGeeks
Tower, Sector-136, Noida, Uttar Pradesh -
201305
Company
About Us
Legal
Careers
In Media
Contact Us
Advertise with us
GF6 Corporate Solution
Placement Training Program
Languages
Python
Java
cH
PHP
GoLang,
Explore
Job-A-Thon Hiring Challenge
HackA-Thon
FG Weekly Contest
Offline Classes (Delhi/NCR)
DSA in JAVA/CH+
Master System Design
Master CP
GeeksforGeeks Videos
Geeks Community
DSA
Data Structures
Algorithms
DSA for Beginners
Basic DSA Problems
DSA Roadmap
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c! 19115417124, 10228M
R Language
Android Tutorial
Data Science & ML
Data Science With Python
Data Science For Beginner
Machine Learning Tutorial
ML Maths
Data Visualisation Tutorial
Pandas Tutorial
NumPy Tutorial
NLP Tutorial
Deep Learning Tutorial
Python Tutorial
Python Programming Examples
Django Tutorial
Python Projects
Python Tkinter
Web Scraping
Opency Tutorial
Python Interview Question
DevOps
it
AWS
Docker
Kubernetes
paure
scp
Devops Roadmap
Data Types in C - GeekstorGecks
Competitive Programming
Web Technologies
HTML
css
JavaScript
Typescript
Reacts
Nextus
NodeJs
Bootstrap
Tailwind CSS
Computer Science
GATE CS Notes
Operating Systems
Computer Network
Database Management System
Software Engineering
Digital Logic Design
Engineering Maths
System Design
High Level Design
Low Level Design
UML Diagrams
Interview Guide
Design Patterns
‘O0AD
System Design Bootcamp
Interview Questions
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c!
sans417124, 10228M
Physics
Chemistry
Biology
Social Science
English Grammar
UPSC Study Material
Polity Notes
Geography Notes
History Notes
Science and Technology Notes
Economy Notes
Ethics Notes
Previous Year Papers
Competitive Exams
JEE Advanced
UGC NET
SSC CG.
SBIPO
SBI Clerk
BPs PO
BPS Clerk
Free Online Tools
‘Typing Test
Image Editor
Code Formatters
Code Converters,
Currency Converter
Random Number Generator
Random Password Generator
Data Types in C - GeekstorGecks
Business Studies
Economics
Management
HRManagement
Finance
Income Tax.
Preparation Corner
Company-Wise Recruitment Process
Resume Templates
Aptitude Preparation
Puzzles
Company-Wise Preparation
Companies
Colleges
More Tutorials
Software Development
Software Testing
Product Management
Project Management
Linux
Excel
AllCheat Sheets
Write & Earn
Write an Article
Improve an Article
Pick Topics to Write
Share your Experiences
Internships
We use cookies to ensure you have the best browsing experience on our website. By using our
site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ntps:www.geekstorgeoks oridata-types-i-c!
1515