C Language

Variable Naming Rules

In C Language by Baqir AliLeave a Comment

What are Variable Naming Rules?

The variable naming rule is a set of rules set in order to name a memory location during coding a program for easy access.

Variable Naming Rules Are The Following

  • Use simple, descriptive variable names.
  • Never use l (lowercase L) or O (uppercase O)   as variable names.
  • Don’t use variable names that differ by only one or two characters. Make every name obviously different from every other name.
  • For variable names consisting of two words joined together, separate the words by “_”: like max_length
  • Use similar names for variables that perform similar functions.
  • When creating a two-word variable name where the words can be put in any order, always put the more important word first.
    •   e.g. max_elevation instead of elevation_max
  • Use standard prefixes:
    • . n_ (“number of”) → n_points
  • Follow every variable declaration with a comment that defines it.

Legal Naming

int leve2;
int total_numbers;
int totalMarks;
float n_points;

Illegal Naming

int 2numbers;
int total marks;
int 22;

Variable Naming Rules

Support us by sharing this post

About the Author

Baqir Ali

Facebook Twitter

Hi, I am Baqir Ali ---- Blogger, Programmer, and a Teacher. I am currently working as a Programmer for Softnat Technologies. I have tons of ideas and data to share with you all via blogging.

Leave a Comment