Rules for constructing variables in C Language

The above video is an extract from the online course – “C Programming: The ultimate guide for beginners” which we are currently working on. Consider subscribing to Youtube channel – Aptuts in order to get latest updates on new videos and online C programming course.

Variables in C are entities 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.

Rules for constructing variables in C

  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:

int variable_name;

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.:

int p, n;
float r;

To learn more about variables in C, visit – Variable, Constant and Keyword in C


C Programming Course (90% Off coupon)

You may also like...

33 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.

  1. October 7, 2020

    […] Here, data-type represents any valid C data-type. E.g. int, char, float, double etc. variable_name can be any valid name satisfying rules for constructing variables in C. […]

Leave a Reply

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

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet