Rules for Constructing Variable Names in C Language

A variable is an entity whose value keeps on changing throughout the program execution. As we all know, data is stored in the memory of the computer. Actually, data is not stored in the variable. A variable is the name given to the memory location. A variable name is an entity that points to a particular memory location.
Variable can be of different types.

Rules for constructing variable names

  1. A Variable name consists of any combination of alphabets, digits and underscores. Some compiler allows variable names whole length could be up to 247 characters. Still it would be safer to stick to the rule of 31 characters. Please avoid creating long variable name as it adds to your typing effort
  2. The first character of the variable name must either be alphabet or underscore. It should not start with the digit
  3. No commas and blanks are allowed in the variable name
  4. No special symbols other than underscore are allowed in the variable name

We need to declare the type of the variable name before making use of that name in the program. Type declaration can be done as follows:

To declare a variable as integer, follow the below syntax:

Here int is the type of the variable named variable_name. β€˜int’ denotes integer type.

Following are the examples of type declaration statements:

E.g.:

You may also like...

32 Responses

  1. Anonymous says:

    nice book

  2. Anonymous says:

    I agree with you. This site is excellent. Great work. Keep going.

  3. Anonymous says:

    gooooooooooood

  4. Anonymous says:

    great work man

  5. Raju says:

    Hi this is raju. Learn c language through online is very good idea . It is very useful to beginners. Already known persons increase their knowledge.

  6. Anonymous says:

    nice work

  7. Anonymous says:

    Goood job…….

  8. LearnCOnline says:

    Thanks to all of you or appreciating my work.

  9. abhinav says:

    can u explain int variable_name nd giv another eg

  10. LearnCOnline says:

    E.g: int flag;
    In the above declaration, flag is a variable that with hold an integer value.

    we can set the value of the above variable as follows:

    flag = 0;

    Here value 0 gets stored in the variable flag.

  11. Anonymous says:

    why cannot the variable name start with a number?

  12. Anonymous says:

    thanxxxxxxxxxxx learnconline

  13. Anonymous says:

    This site and its tutorial on C programming is off the hook

  14. Anonymous says:

    good jOb admin

  15. Anonymous says:

    marvellous……

  16. Anonymous says:

    Awesome :):)

  17. LearnCOnline says:

    Thank you everyone for the wonderful comments. I hope this website is helping every one out there.

    If you like this website, kindly share it with everyone.

    Thanks,
    LearnCOnline Team

  18. Juhi Kumari says:

    as told no special character is allowed.
    Why $jd is a variable?

  19. Anonymous says:

    try to create a variable with name $a, it gets compiled using gcc

  20. Anonymous says:

    nice piece

  21. Anonymous says:

    helped a lot
    thx

  22. anoop says:

    wht r different rules to define a variable with example

  23. jackson says:

    i appreciate the good work

  24. MAHALAKSHMI.S says:

    NIce to see ur website, As a Professor I can learn more with the use of ur web-site………Congrats & Keep this great wrk

  25. achyuth says:

    I agree with you. this site is excellent

  26. Remmy says:

    Truly! Simple and crystal clear. Good job bro.

Leave a Reply

Your email address will not be published. Required fields are marked *