Variables in C


Variables in C Programmings:-

"Variable in C" variables names are case sensitive whose value can change any time. It is a memory location used to store data value. A variable name in C variables should be carefully chosen so that its use is reflected in a useful way in the entire program. 


Rules for declaring variables in C Programming:-

  1. They must always begin with a letter, although some systems permit underscore as the first character.
  2. The length of a variable must not be more than 8 characters.
  3. White space is not allowed and
  4. A variable should not be a Keyword
  5. It should not contain any special characters. 
In C variables A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable. A variable definition has its meaning at the time of compilation only, the compiler needs actual variable definition at the time of linking the program. A variable declaration is useful when you are using multiple files and you define your variable in one of the files which will be available at the time of linking of the program. You will use the keyword ex-tern to declare a variable at any place. Though you can declare a variable multiple times in your C program, it can be defined only once in a file, a function, or a block of code.

  • A variable is a value that can change any time
  • It is a memory location used to store a data value
  • A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program.
  • Variable names are case sensitive. 

Examples of valid variable names are:
                a              A
                Sun        SUN       sUN       
                number               
                Emp_name        
                average1
                _Salary

Examples of Invalid Variable names are:
                123
                (area)
                6th
                %abc

    // Variable declaration:
    extern int a, b;
    extern int c;
    extern float f;
    int main () {
       /* variable definition: */
       int a, b;
       int c;
       float f;
       /* actual initialization */
       a = 10;
       b = 20;
       c = a + b;
       printf("value of c : %d \n", c);
       f = 70.0/3.0;
       printf("value of f : %f \n", f);
       return 0;
    }

    When the above code is compiled and executed, it produces the following result −

    • value of c : 30
    • value of f : 23.333334


    Sr.No.
    Type & Description
    1
    char
    Typically a single octet(one byte). This is an integer type.
    2
    int
    The most natural size of integer for the machine.
    3
    float
    A single-precision floating point value.
    4
    double
    A double-precision floating point value.
    5
    void
    Represents the absence of type.



    Comments

    Popular posts from this blog

    C Program for SCAN Disk Scheduling Algorithm | C Programming

    C program to Find Cartesian Product of Two Sets | C programming

    C Program To Check The String Is Valid Identifier Or Not | C Programming