Wednesday 15 January 2014

Variable and Data Types:

Variable is a space or location (RAM), which has a unique name and may contain any value. The value could be an integer value like ‘11’, a decimal/float value like ‘3.56’, or a character value like ‘S’.

Example:-  Int x;--Here ‘x’ is the variable name.
                    Char y;--Here ‘y’ is the variable name.
          Float k;  --Here ‘k’ is the variable name.
·        Variable’s value has not static or fixed.

Rules for Naming Variables in C :-
  1. Variable names should not have any embedded space or symbols such as ? ! @ # % ^ & + - * ( ) { } . , ; :  “ ‘ / \. However, an underscores ‘_’ can be used wherever a space is required, For example:- ‘Dennis_Ritchie’.
  2. Variable names must be unique. (C is a case-sensitive language).
  3. A variable name must begin with a letter or an underscore. The first character in a variable name cannot be a digit.
  4. Keywords cannot be used as variable names. For example:- you cannot declare a variable named ‘void’ or ‘int’.



Examples of Variable Names :-



Data Types:-  The type of data that can be stored in a variable.
Char:- For character.
Int:- For integer.
Float:- For numbers with decimals.

Data type can be catagorized in two types:-
1.Value Type. Ex. Char,int.
2.Referance Type. Ex. String.


Since the above data types are represented at the machine level, the storage requirement is hardware dependant. The following picture show the storage requirements for the data types.




No comments:

Post a Comment

Thanks For Giving Comment In Our Blog.