C Programming Data Types
C Programming Data Types
CProgrammingDataTypes
CProgrammingDataTypes
In this tutorial, you will learn about data types and how to declare a variable in C
programming.
InCprogramming,variablesormemorylocationsshouldbedeclaredbeforeitcanbeused.
Similarly,afunctionalsoneedstobedeclaredbeforeuse.
Datatypessimplyreferstothetypeandsizeofdataassociatedwithvariablesandfunctions.
DatatypesinC
1.FundamentalDataTypes
Integertypes
Floatingtype
Charactertype
http://www.programiz.com/cprogramming/cdatatypes
1/4
8/4/2016
CProgrammingDataTypes
2.DerivedDataTypes
Arrays
Pointers
Structures
Enumeration
Thistutorialwillfocusonfundamentaldatatypes.Tolearnaboutderiveddatatypes,visitthe
correspondingtutorial.
Integerdatatypes
Integersarewholenumbersthatcanhavebothpositiveandnegativevalues,butnodecimal
values.Example:0,5,10
InCprogramming,keywordintisusedfordeclaringintegervariable.Forexample:
intid;
Here,idisavariableoftypeinteger.
YoucandeclaremultiplevariableatonceinCprogramming.Forexample:
intid,age;
Thesizeofintiseither2bytes(InolderPC's)or4bytes.Ifyouconsideranintegerhaving
sizeof4byte(equalto32bits),itcantake2 32distinctstatesas:2 31,2 31+1,...,2,1,0,
1,2,...,2 312,2 311
Similarly,intof2bytes,itcantake2 16distinctstatesfrom2 15to2 151.Ifyoutrytostore
largernumberthan2 311,i.e,+2147483647andsmallernumberthan2 31,i.e,
2147483648,programwillnotruncorrectly.
Floatingtypes
Floatingtypevariablescanholdrealnumberssuchas:2.34,9.382,5.0etc.Youcandeclare
afloatingpointvariableinCbyusingeitherfloatordoublekeyword.Forexample:
floataccountBalance;
doublebookPrice;
http://www.programiz.com/cprogramming/cdatatypes
2/4
8/4/2016
CProgrammingDataTypes
Here,bothaccountBalanceandbookPricearefloatingtypevariables.
InC,floatingvaluescanberepresentedinexponentialformaswell.Forexample:
floatnormalizationFactor=22.442e2;
Differencebetweenfloatanddouble
Thesizeoffloat(singleprecisionfloatdatatype)is4bytes.Andthesizeofdouble(double
precisionfloatdatatype)is8bytes.Floatingpointvariableshasaprecisionof6digits
whereastheprecisionofdoubleis14digits.
Charactertypes
Keywordcharisusedfordeclaringcharactertypevariables.Forexample:
chartest='h'
Here,testisacharactervariable.Thevalueoftestis'h'.
Thesizeofcharactervariableis1byte.
CQualifiers
Qualifiersaltersthemeaningofbasedatatypestoyieldanewdatatype.
Sizequalifiers
Sizequalifiersaltersthesizeofabasictype.Therearetwosizequalifiers,longandshort.
Forexample:
longdoublei;
Thesizeoffloatis8bytes.However,whenlongkeywordisused,thatvariablebecomes10
bytes.
LearnmoreaboutlongkeywordinCprogramming.
Ifyouknowthatthevalueofavariablewillnotbelarge,shortcanbeused.
http://www.programiz.com/cprogramming/cdatatypes
3/4
8/4/2016
CProgrammingDataTypes
Signqualifiers
Integersandfloatingpointvariablescanholdbothnegativeandpositivevalues.However,ifa
variableneedstoholdpositivevalueonly,unsigneddatatypesareused.Forexample:
//unsignedvariablescannotholdnegativevalue
unsignedintpositiveInteger;
Thereisanotherqualifiersignedwhichcanholdbothnegativeandpositiveonly.However,it
isnotnecessarytodefinevariablesignedsinceavariableissignedbydefault.
Anintegervariableof4bytescanholddatafrom231to2 311.However,ifthevariableis
definedasunsigned,itcanholddatafrom0to2 321.
Itisimportanttonotethat,signqualifierscanbeappliedtointandchartypesonly.
Constantqualifiers
Anidentifiercanbedeclaredasaconstant.Todosoconstkeywordisused.
constintcost=20;
Thevalueofcostcannotbechangedintheprogram.
Volatilequalifiers
Avariableshouldbedeclaredvolatilewheneveritsvaluecanbechangedbysomeexternal
sourcesoutsidetheprogram.Keywordvolatileisusedforcreatingvolatilevariables.
Checkouttheseexamplestolearnmore:
CProgramtoPrintanIntegerEnteredbytheUser
CProgramtoAddTwoIntegers
CProgramtoMultiplytwoFloatingPointNumbers
PreviousPage
NextPage
CopyrightbyProgramiz|Allrightsreserved|PrivacyPolicy
http://www.programiz.com/cprogramming/cdatatypes
4/4