ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

C Programming Lesson - Data Types in C Language

Updated on September 29, 2014
Source

A programming language helps us process certain kinds of data by providing useful output. The task of data processing is accomplished by executing a series of commands called a program. A program usually contains different types of data, such as integer, float, character etc. A program stores the values being used along with a library function and the user defined function (UDF) to process that stored data. C language is rich in data types and library functions.

C data types can be broadly classified as :

  1. Primary data types
  2. Secondary data types

Data Types in C

Primary Data Types in C Language

Primary data types include the following:

  • Integer
  • Float
  • Character
  • Void

Integer Data Type

  • Integers are whole numbers with a range of values, the range limits being machine dependent.
  • Denoted by the keyword int.
  • Generally an integer occupies 2 bytes memory space and its value range is limited to -32768 to +32767 (that is, -215 to +215-1).
  • A signed integer uses one bit for storing the sign and 15 bits for the number.

To control the range of numbers and storage space, C has three classes of integer storage:

  1. short int
  2. int
  3. long int

A short int requires half the amount of storage than normal integer. The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space.

All three data types have signed and unsigned forms.

  • Unlike signed integers, unsigned integers are always positive and use all the bits for the magnitude of the number. Therefore the range of an unsigned integer will be from 0 to 65535.

Syntax: int <variable name>; like
int num1;
short int num2;
long int num3;

Example: 5, 6, 100, 2500.

Integer Data Type Memory Allocation

Primary Data Types in C: Float

  • The float data type is used to store fractional numbers (real numbers) within 6 digits of precision.
  • Floating point numbers are denoted by the keyword float.
  • When the accuracy of the floating point number is insufficient, we can use the specifier "double" to define the number. “Double” is the same as “float” but has double the precision and takes up twice as much memory space (8 bytes) as float.
  • For even more precision we can use “long double” which occupies 10 bytes of memory space.


Syntax: float <variable name>;

like:
float num1;
double num2;
long double num3;

Example: 9.125, 3.1254.

Floating Point Data Type Memory Allocation

Memory allocation of float data in C.
Memory allocation of float data in C.

Primary Data Types in C: Character

  • The character type variable can hold a single character.
  • "Char," like "int," may be singed or unsigned. Both signed and unsigned occupy 1 byte each but have different ranges. Unsigned characters have values between 0 and 255; signed characters have values from –128 to 127.
  • Denoted by char.


Syntax: char <variable name>;

like:
char ch = ‘a’;

Example: a, b, g, S, j.

Primary Data Types in C: Void

  • The “void” data type returns no data; it is not a variable like the other types. It may be used with functions that need to be run without returning any values.
  • For example, we can declare “main()” as a void type because it does not return any value.

User-Defined Type Declaration in C Language

C language supports a feature where the user can define the identifier that characterizes an existing data type. This user-defined data type identifier can later be used to declare variables. In short, its purpose is to redefine the name of an existing data type.

Syntax: typedef <type> <identifier>;

Example: typedef int number;

Now we can use number in lieu of int to declare integer variable. For example: if we enter int x1 or number x1 both statements declare an integer variable. We have just changed the default keyword int to declare integer variable as number.

Size and Range of Data Types in C Language

This chart shows you how much space each data type like int, char, float occupies in memory, along with its data range and the keyword used by the C programmer.
This chart shows you how much space each data type like int, char, float occupies in memory, along with its data range and the keyword used by the C programmer.

Secondary Data Types in C Language

  • Arrays: collections of data of a similar type.
  • Pointers: a way to refer to information by referring to the address where the information is kept.
  • Structures: a way of associating data of different types.
  • Unions: a way of allowing the same data to be read as data of different types.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Obzy 5 months ago

      What is the size and range of viod

    • profile image

      diksha koushal 2 years ago

      its nice

    • nicomp profile image

      nicomp really 2 years ago from Ohio, USA

      The char type should not be confused with a character. It's simply a 1-byte integer, usually. It can 'hold' any integer value within the given range. A one-byte signed char, for example, has the range -128 through +127.

    • profile image

      Aadil Syed 3 years ago

      awesom programing c but its vry complicated......

    • profile image

      nikita 4 years ago

      thanks for information

    • profile image

      ss 4 years ago

      its nice

    • profile image

      mushkin 4 years ago

      thanks its very easy to understand,not any confuse

    • profile image

      rajendra 4 years ago

      please give me all notes of c langauge with programme........

    • profile image

      manjunath 4 years ago

      its very useful to students thank u

    • profile image

      udhayan 4 years ago

      than q very much....this helped me a lot:)))

    • profile image

      sania angle 4 years ago

      thank u..............

    • rajkishor09 profile image
      Author

      RAJKISHOR SAHU 4 years ago from Bangalore, Karnataka, INDIA

      Well said @sonuxrt, I published this article on this site on 04/07/2009 and that site came into existence on Sat, 26 Nov 11 11:14:14 +0400 see link http://eazynotes.com.whoisbucket.com I didn't know know that I am so good in copying content :P.

    • profile image

      sonuxrt 4 years ago

      www.eazynotes.com/notes/c/notes/data-types-in-c-language.pdf

      Don't copy from another website

    • Programminghub profile image

      Programminghub 4 years ago from India

      Really a nice post Dear...:)

      I created a facebook, from where you can download lots of free ebooks and tutorials....(in a single click only..)

      C, C++ and JAVA programming tutorials + Much More..

      Thank You Raj Kishor..

    • profile image

      ALI 5 years ago

      ooooooooooooooooooooooo

    • profile image

      Pinku Hazra 5 years ago

      By this answer am very helpful,..thanks keep on.

    • profile image

      ramesh 5 years ago

      kolaveri

    • profile image

      ian05 5 years ago

      very helpful... keep it up, do some more... great job.

    • profile image

      jhezrylle 5 years ago

      anu po ung mga Variables ng c language?/

    • profile image

      jawadmalik 5 years ago

      its working ... :)

    • rajkishor09 profile image
      Author

      RAJKISHOR SAHU 5 years ago from Bangalore, Karnataka, INDIA

      thanks for visiting my friend...

    • profile image

      waqas Amanat 5 years ago

      its really a very helpful for students & others. it helped me a lot in my exams..thankx a lot

    • profile image

      Masabo Christophe 5 years ago

      thank you for teaching, then you add more programms

      ok

    • profile image

      simran 5 years ago

      thanks for uploading this information

      really its very help me

    • profile image

      abhinav vats 5 years ago

      it is very helpful so plz keep it up

    • profile image

      magoo 5 years ago

      that was short and precise, thank you!

    • profile image

      Hasnain 5 years ago

      If any one have any good material regarding c & c++,plz send me at shasnainraza92@aol.com

    • profile image

      Ramisha Rukhsar 5 years ago

      plz tell me about the problems of floating point used in c programming language.plz tell me ans as soon as possible

    • profile image

      monisha 5 years ago

      what is abstract datatype?

    • profile image

      Arun Mavi 5 years ago

      It is hard for UP board students only otherwise it is easy

    • profile image

      priyanka 5 years ago

      Thanks, it helps me a lot

    • Java Programs profile image

      Java Programs 5 years ago from India

      Excellent hub on Data types in C.... I am also a software developer and have started writing for hubpages under category of Java. I have published my first hubs as :

      http://javaprograms.hubpages.com/hub/Introduction-...

      have a look .... Thanks for the wonderful information...

    • profile image

      ankur 5 years ago

      can u tell me where the data type store in comp.memory

    • profile image

      jaswant kumar 5 years ago

      i think four batter c program tools this web site

    • profile image

      anchal 5 years ago

      kuch samajh nah araha

    • profile image

      santhosh kumar 5 years ago

      it's intresting..... but i dnt know c program.....

      pls help me....

    • profile image

      raj 5 years ago

      why we need range for datatype like int as -32708 to 32627?

    • profile image

      mekhzam 5 years ago

      this is very nice

    • profile image

      Ajay bidhauliya 5 years ago

      need to few is described

    • profile image

      Ajay PAtil 5 years ago

      @rajkishor09 ::::::::::::::?????????????????

      if knw the correct ans den only post otherwise don't post..............don't misguide to people.......plz

      who told u dat structure is NOT user defined data type,,,,,,,,,,,,,,,,,,,,buddy

      its user defined data type ..pgmer only define types of variables which u Want..................so plzzzzzzzzzzz u knw correcr n accurate ans den post otherwise don't post

    • profile image

      kalpana 5 years ago

      so confuse and so boring

    • profile image

      ravi ranjan 5 years ago

      gooooooooooddddd

    • fahad akhtar profile image

      fahad akhtar 5 years ago from pakistan

      plzzzz give me about the idea of modulus in algorithm

    • profile image

      sree 5 years ago

      i dont know c.how to do the programs,so plz give me a suggestion to over come the problem

    • profile image

      Md Ali Umar 5 years ago

      for double %lf & for long double %Lf, for short signed int %d, short unsigned int %u.

      aliumar.in@gmail.com

      Bhagalpur,

      Bihar,

      India.

    • profile image

      INSI 5 years ago

      WAT IS USE OF * IN SCANF STATEMAENT?

    • profile image

      dude 5 years ago

      how can i print these data types i mean like %d for integer... what for double, long double and short int etc

    • profile image

      supriya,s.p.jain college 5 years ago

      thank's for deeply information

    • profile image

      saanraja@yahoo.com 5 years ago

      thankyou very much...............this provides us many hints for further study

    • profile image

      Nibedita Swain 5 years ago

      What variable? explane pointer variable

    • profile image

      md wakash ahmad 5 years ago

      why uses # in c program

      please reply this topic on that site

    • profile image

      kanchan Pande 5 years ago

      Can any one tell me,that there are how many data types included in C and C#.

    • profile image

      Sanket Sathe 5 years ago

      Awesum...

    • profile image

      sanjeev kumar 5 years ago

      i am define int a=015 and print the value is 13 why plz rply me urgently

    • profile image

      kamaluddin ahmed 5 years ago

      i want to make indian national flag but how ,i have no idea ,please give me some tips

    • profile image

      glorious143@hotmail.com 5 years ago

      what's the mean by recursion?

    • profile image

      aruna devi 5 years ago

      what are data types in c?

    • profile image

      krish 5 years ago

      very fine historical and briefly knowledge of c. good one

    • profile image

      codeguru 6 years ago

      this article is so so not good

    • profile image

      arvnagendrakumar5 6 years ago

      i love c programs

    • profile image

      bk 6 years ago

      Too nice sis it is very koalaveru da

    • profile image

      adil khan 6 years ago

      no compiler not depend on variable..........

    • profile image

      Raj 6 years ago

      am a student of cse but from bio background so plz help me my email id is-rajnandi15992@gmail.com

    • profile image

      mobigujjar 6 years ago

      I m a stdnt of BS(IT)

      plz u help me in this field

      plz snd email address to me

      mobigujjar02@gmail.com

    • profile image

      Vamshi 6 years ago

      Nice site bro..

      It is very use full...

    • profile image

      yasir lovee 6 years ago

      ThankU sir,,,

      Jst a question that U have not used in data types that is ''Format'' of these data types.Plz justify if so........

    • profile image

      prince suwalka 6 years ago

      c lang is very mindblowing lang

    • profile image

      cheryl 6 years ago

      what is the importance of the sizes of the data types in c language?

    • profile image

      all bca 6 years ago

      c language is so so so so so so easier dude

    • profile image

      Sunti Lhatdavong 6 years ago

      I like C language

    • profile image

      chitti 6 years ago

      i gave a seminar using this

    • profile image

      chitti 6 years ago

      thnk u bro 4 such a good expl

    • profile image

      chitti 6 years ago

      thnk u

    • profile image

      chitti 6 years ago

      gud expl

    • profile image

      nikhil so.... 6 years ago

      thank u very much ...:)

    • profile image

      jhin_jhin 6 years ago

      i liKe it.

    • profile image

      dinesh 6 years ago

      thank u very much i answered my viva question in my practical session by using this site

    • profile image

      faizkiki family 6 years ago

      thank u

    • profile image

      fasial 6 years ago

      its support very well for my exam

    • profile image

      mohd kashif 6 years ago

      great work

    • profile image

      ravi 6 years ago

      @ sai ram

      which branch r u ??

    • profile image

      sai ram 6 years ago

      i m from b v raju college,studying 1st year,narsapur,medak.

      .....please teach me c bro....

    • profile image

      sai ram 6 years ago

      i know c but i don't knw.... c language wt to do....bro... i beg u teachh c plz bro i touch u r feet..... my num is 9000932558

    • profile image

      chinni 6 years ago

      its very nice & easy to understand if da logics are clear

    • profile image

      m kashif 6 years ago

      simple but easy to understand. so execelent

    • profile image

      Ravi 6 years ago

      The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie foruse on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications.

    • profile image

      srinu 6 years ago

      if we have an intrest, then can we learn this subject very easily,,,,,

    • rajkishor09 profile image
      Author

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Parvez size of any data type is compiler dependent.

    • profile image

      ruji 6 years ago

      what is c plz tell me ....

    • profile image

      Parvez 6 years ago

      Why dos integer datatype in c take 4 bytes in visual studio ?

      plsss reply back!!!

    • profile image

      teja 6 years ago

      what is the use of %u in c language

    • profile image

      Syed Zaheer 6 years ago

      This web side is awesome, i got good notes for c n have also learn answers soo tnks

    • profile image

      vallabhi 6 years ago

      love U C................Learning U is just playing with a friend

    • profile image

      Karan 6 years ago

      Thanks.....Raj

    • profile image

      suyash47 6 years ago

      Array in C programming

      An array in C language is a collection of similar data-type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int,...

    • profile image

      sajan 6 years ago

      i luve studyin c programming. studying

    • profile image

      sajan 6 years ago

      i love c programming its very useful.

    • profile image

      rahul 6 years ago

      i want to know about c, its very intresting, but also hard for me.

    • profile image

      tamanna 6 years ago

      too difficult and bkkwwaaaaaaaaasss

    • profile image

      twinkle 6 years ago

      i hate c i don't like 'c' language okkkkkkkkkkk