C Variable, Datatypes, and Constants

                                        


What   is  a  'C'  variable?

       A  variable  is  an  identifier  which  is  used  to  store  some  value .

       Constant  can  never  changes  at  the  time  of  execution. Variables 

        can  change  during  the execution  of  a  program  and  update  the

        value stored  inside  it.

       A  single  variable  can be  used  at  multiple  locations  in  a  program. 

       A  variable  name  must  be  meaningful. It  should  represent  the  purpose

       of  the   variable.

       A  variable  must  be  declared  first  before  it  used  somewhere inside  the 

       program.  A   variable  name  is  formed  using  characters , digits  and

       underscore.

   Following are  the  rules  must be followed  while  creating  a  variable:

      1.  A  variable  name  should  consists  of  only  characters, digits, and  an 

          underscore.

     2.   A  variable  name  should  not  begin  with  a  number .

     3.   A   variable  name  should  not  consist  of  whitespace .

     4.   A  variable  name  should  not  consist  of  a  keyword.

     5. 'C'  is  a  case  sensitive   language  that  means  a  variable  named  'age'  

           'AGE'  are  different.

      Following  are  examples of  valid  variable  names  in  'C'  program:

     1.  height

     2.  _height

     3.  height2    

        

  Data   types:

      'C'   provides  various  data types  to  make  it  easy  for  a  programmer  to  select

       a  suitable  data type as  per  the requirements  of  an  application.

       Following  are  the  three  data  types:

       1.  Primitive  data  types

       2.  Derived  data  types

       3.  User  defined   data  types

    There  are  five  primary  fundamental  data  types,

       1.  int  for  integer  data 

       2.  char  for   character  data  

       3.  float  for  floating  point   numbers 

       4.  double  for  double  precision  floating  point  numbers 

       5 .  void 

  Integer  data  type :

          Integer  is  nothing  but  a  whole  number .  The  number  for  an  integer data  

          type  varies  from  machine  to  machine. The  standard  range  for  an  integer  

          data  type  is  -32768  to  32767.

          An  integer  typically  is  of  2  bytes  which  means  it  consumes  a  total  of  16 

          bits  in  memory.

          A   single  integer  value  takes  2  bytes  of  memory. An  integer  data  type   is

         further  divided  into  other  data  type  such  as  short  int ,  int , and long  int.

         When  ever  we  want  to  use  an  data  type ,  we  have  place  int  before  the  

          identifier  such   as ,

           int  age;

           Here, age  is  a  variable  of  an  integer  data  type  which  can  be  used  to  store  

           intger  values.

Floating  point  data  type:

           The  'float'  keyword  is   used  to  represent  the  floating  point  data  type. It  can 

            can  hold  a  floating  point  value  which  means  a  number  is  having  a  fraction 
             

            and   a  decimal   part.  A  floating  point  value  is  a  real  number  that  contains 

            a  decimal   point.  Integer  data  type  doesn't  store  the  decimal   part   hence  we

            can  use   floats   to   store  decimal   part   of   a  value.   

Here  some  examples  are:

          float   division;

          double  Bank balance;

Character  data   type

          Character   data  type  are  used  to  store  a  single  character  value  enclosed  in  single                   

          quotes.  A  character  data  type  takes  up  to  1  byte  of  memory  space.

Example:

           char   letter;

Void  data  type :

           A  void  type  doesn't   or  return  any   value.  It  is  mostly  used  for  defining   

           function  in  'C'.

Constants:

          Constant  are  the  fixed  value   that  never  change  during  execution  of   a   program.

          Following  are  the  various  types  of  constants.

          1.  Integer  constants

          2.  Character  constants

          3.  String  constants

          4.  Real  constants


        1. Integer  constants:

            An  integer  constant  is  nothing  but  a  value  consisting  of  digits  or  numbers.  These 

            values  never  change  during  the  execution   of  a  program.  Integer  constant  can  be  

            octa, decimal, and hexadecimal .

         1. Decimal  constant  contains  digits  from  0  - 9 such  as :

    Example:  124, 135 


         2. Octa  constant  contains  digits  from  0-7 , and these  types  of  constants  are  always

             preceded  by 0.

Example:  012,  067

         3.  Hexadecimal   constant  contains  a  digits  form  0-9 as  well  as  characters  from A-F.

             Hexadecimal   constants  are  always  preceded  by  0X.

Example:  0X2,  0Xvd

  

             

2.  Character  constants:

          A  character  constant  contains  only  a  single  character  enclosed  within  a  single 

          quotes(").

Example:

               'V' ,  'D' ,  '9'

3.  String  constants:

         A  string  constant  contains  a  sequence  of  character  enclosed  within  double  quotes(" ")

Example: 

         " Hello" , "programming"

4.  Real  constants: 

         'C'  also  provides  real  constants  that  contains  a  decimal  point  or  a  fraction  value. 

          The  real  constant  are  also  called  as  floating  point  constants. The  real  constants  

          contains  a  decimal  point  and  a  fraction  value.

Example:

         202.23 , 3000.00

 Summary

      1.  A  constant   is  a  value  that  doesn't  change  throughout  the  execution  of   a  program.

      2.  A  variable  is  an  identifier  which  is  used  to  store  a  value.

      3.  There  are  four  commonly  used   data  type  such  as  int , float , char  and  a  void .

      4.  Each  data  type  differs  in  size   and  range  form  one   to  another .


               Created  By :  VISHAL  YADAV

                                                      Thank   you

1 Comments

Comment from message

Post a Comment

Comment from message

Previous Post Next Post