Skip to main content

[SSC II] Computer Science SLO 8.4.2

 

Computer Science SSC II Notes - AKUEB

8.4.2 List the rules for specifying variable names;

 

             When specifying variable names in the C programming language, there are certain rules and conventions to follow.

 

Here are the key rules for naming variables in C:

 

1. Valid characters: Variable names can consist of letters (both uppercase and lowercase), digits, and underscores (_). They must start with a letter or an underscore. Special characters and spaces are not allowed.

 

2. Case-sensitive: C is a case-sensitive language, so uppercase and lowercase letters are considered distinct. This means that variables named "myVariable" and "myvariable" are treated as separate entities.

 

3. Reserved words: You should avoid using C reserved words (also known as keywords) as variable names. These reserved words have predefined meanings in the language and cannot be used as identifiers. Some examples of reserved words in C include "int," "float," "for," "if," and "while."

 

4. Meaningful and descriptive: Choose variable names that are meaningful and descriptive of the data they represent. This helps in improving code readability and understanding. For example, instead of using single-letter variable names like "x" or "y," consider using more descriptive names like "age," "temperature," or "studentName."

 

5. Length limitations: Variable names in C can be of any length, but only the first 31 characters are significant. However, it is recommended to keep variable names reasonably concise and avoid excessively long names for the sake of code readability.

 

6. Underscore convention: It is common in C programming to use underscore convention for multi-word variable names. In the underscore convention, words are separated by underscores (_). Choose one convention and be consistent throughout your codebase. Here are examples of conventions:

      - Underscore convention: my_variable, student_age, number_of_students

 

 

Cognitive Level: Knowledge


Comments

© 2020 NEXUS NOTES

Designed by Open Themes & Nahuatl.mx.