Rules
for naming Variable on C?
Definition:
A variable is a named storage location in a computer program's memory that stores a value or a reference to a value. Variables are used to store data values and can be used to hold any type of data, such as numbers, strings, or objects. The value stored in a variable can be changed during the execution of a program, making them very useful for storing and manipulating data. Variables are typically declared and initialized with a specific data type and are often used in control flow statements and loops to control the flow of a program.
Rules For Naming Variables |
Rules For Naming Variables on C:
1.
Variables are Case Sensitive: This means
that a variable named "example" is different from a variable named
"Example" and the variables can be used independently without any
conflicts.
Note: A=50
and a=50 are two different variables.
2.
Only starts with '_' or English alphabets:
Variables in C must start with an underscore or an English alphabet. This means
that variables cannot start with numbers or special characters.
Note:
_a=50 is Valid
-a=50 is
invalid.
3.
No Comma or Blank Spaces: Variables
cannot contain any commas or blank spaces in their names. This means that a
variable cannot be named "example, test" or "example test".
Note:
num,data=50 is
invalid
num data=50 is
invalid
4. No other symbol than '_': Variables can only contain the underscore symbol as a special character in their names. All other special characters are not allowed in variable names.
Rules |
Example:
Valid |
Invalid |
int
_private_variable; int
publicVariable; int
firstName; |
int 1stName;
//starts with a number int
first-name; //contains a special character other than '_' int first
name; //contains a blank space int
first,name; //contains a comma |
In the above example, the first variable _private_variable is valid because it starts with an underscore. The second variable publicVariable is valid because it starts with a letter. The third variable firstName is also valid because it starts with a letter and doesn't contain any spaces or special characters other than '_'. The other examples are invalid because they do not follow the naming rules specified.