Tips and Tricks for declaring variables | C Weekly | Power Of C
Tips and Tricks for declaring variables
Declaring variables is not a easy task. It is a difficult and mind confusing task. So here, I am providing some tips that can help you to declare variables easily in C Programming.
Always try to follow the following points :
1. Every variable name must start with a letter(a-z , A-Z) or a underscore( _ )
2. Never start a variable name with numbers,symbols,etc
3. A variable should not contains special characters like $ < * & ^ % #, etc
4. A variable can contain only digits,letters(it may be upper case or a lower case),underscore
5. Variables must be realistic and connected to real life problem, for example if you are writing a program for calculating total marks of student then use the variables like total_marks,etc
6. Do not use short,letter names. for example, to store student total marks don't use the variables like a,b,f,m,etc. they are confusing names.
7. Avoid too much long names.
8. You can use following naming pattern.
* Camel Case : In this case the first letter of each word in a compound word is capitalized. For example, variable for total marks in camel case can be written as TotalMarks.
In this letter 'T' of total and letter 'M' of marks is capitalized.
* Pascal Case : In this case, generally the first letter of every word in a compound word is capitalized except that the first letter of first word is in lower case. For example,variable for total marks in pascal case can be written as totalMarks.
In this only 'M' of marks is capitalized.
9. Naming a variable is case sensitive. It means that Marks and marks is different and they are different variables. It is better to avoid such situations.
10. Never use a reserved keyword of C for naming a variable. For example,you cannot use void as a variable name.
11. The global variable's name should be start with a capital letter i.e. Global_var.
12. Local variable's name should be start with a small letter i.e. local_var.
13. Constant variable's name should be in all capital letters i.e.
PIE etc.
14. The variables with short life time should be of short name i.e. i, j, k.
15. The variables which have long life time should be of long name as rate_of_intrest etc.
11. The global variable's name should be start with a capital letter i.e. Global_var.
12. Local variable's name should be start with a small letter i.e. local_var.
13. Constant variable's name should be in all capital letters i.e.
PIE etc.
14. The variables with short life time should be of short name i.e. i, j, k.
15. The variables which have long life time should be of long name as rate_of_intrest etc.
Good... 👍
ReplyDeleteGood 👍 steps for knowledge gain
ReplyDeleteSir really helpful tricks
ReplyDeletehey guys this content is really good ...and thanks for providing us this useful content....
ReplyDelete