Definition of variable in c

Definition of variable in C programming language:

A variable is named location of data. In other word we can variable is container of data.

    In real world you have used various type containers for specific purpose. For example you have used suitcase to store clothes, match box to store match sticks etc. In the same way variables of different data type is used to store different types of data. For example integer variables are used to store integers char variables is used to store characters etc. On the basis of how many data a variable will store, we can categorize the all c variable in three groups.

(a)Variables which can store only one data at time. Example: integer variables, char variables, pointer variables etc. 

(b)Variables which can store more than one data of similar type at a time. Example: array variables

(c) Variables, which can store more than one value of dissimilar type at a time. Example: structure or union variables.

Properties of variable in c:

    Every variable in c have three most fundamental attributes. They are:

1. Name

2. Value

3. Address

Name of a variable:

 Every variable in c has its own name. A variable without any name is name is not possible in c. Most important properties of variables name are its unique names. Not two variables in c can have same name with same visibility. For example:

#include<stdio.h>
int main(){
    auto int a=5;   //Visibility is within main block
    static int a=10; //Visibility is within main block

/* Two variables of same name */
    printf("%d",a);
    return 0;
}

Output: compilation error

But it is possible that two variable with same name but different visibility. In this case variable name can access only that variable which is more local. In c there is not any way to access global variable if any local variable is present of same name. For example:

(a)

#include<stdio.h>
int a=50; //Visibility is whole the program

int main(){
    int a=10; //Visibility within main block
    printf("%d",a);
    return 0;
}

Output: 10

(b)

#include<stdio.h>

int main(){
    int a=10; //Visibility within main block.
    {
        a+=5; //Accessing outer local variable a.
        int a=20; //Visibility within inner block.
        a+=10; //Accessing inner local variable a.    
        printf(“%d”,a);//Accessing inner local variable a.
    }

    printf(“%d”,a); //Accessing outer local variable a.
    return 0;
}

Output: 30 15

Note: In c any name is called identifier. This name can be variable name, function name, enum constant name, micro constant name, goto label name, any other data type name like structure, union, enum names or typedef name.


25 comments:

  1. I have just started learning computer programming. I found this website very informative. It will help me to get some good programming concepts.

    ReplyDelete
  2. very nice material .......

    ReplyDelete
  3. Many many thanks

    ReplyDelete
  4. i am a beginner and i only study from this website only and it is providing me much needed confidence

    ReplyDelete
  5. it provides good study material ..

    ReplyDelete
  6. Nice tutorial....great job god bless you

    ReplyDelete
  7. ppppppppppppppppppp
    jasani

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. thank you so much very nice tutorials its really helped me alot...

    ReplyDelete
  10. good creation..........

    ReplyDelete
  11. this tutorial is really very useful

    ReplyDelete
  12. This has been an awesome collections of knowledge.

    ReplyDelete
  13. thank u very much for providing excellent material...it will help us a lot........thanQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ

    ReplyDelete
  14. thanx very much for providing dis material :) itz very usefullllll

    ReplyDelete
  15. Super Website....

    ReplyDelete
  16. i am happy.....usually i never participate for comment something........but,now can't able to control myself without commanding your site...............
    my heartful thanks to you..................................

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. for (i=0; i<1000000; i++)
    {
    printf ("Realy realy nice explaination, i cant control myself from commenting on your site....:) ");
    }

    Thanks a lot............

    ReplyDelete
  19. i found this site very informative
    thank you

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. as a student of CSE i am learning c programming,this website helping a lot,thanks

    ReplyDelete
  22. Thank you so much very nice material its really helped me alot...

    ReplyDelete