- click here to know what are variables and identifiers
- Look friend to make conversation with a person with other language we need to follow some words and grammar in his language other wise it may lead us to talk some bad words which may revert us in negative .
- Similarly while we interacting with computer we need to follow rules in coding to create variables or identifiers otherwise system will revert us with errors
- Rules to create Identifiers or Variables
- In an identifier we can use uppercase alphabets, lowercase alphabets ,numbers(whole numbers) and underscore('_') .
- We cannot start a variable name with numbers .
- Either the name should start with alphabets or '_' .
- We should not use any other special characters or spaces .
- Examples for special characters - '!','@','#','$',etc.,
- We also should not use keywords or reserved words like int ,const ,void , float , char ,etc.,
- Here are some correct examples to select variables
- int price = 32 , char Covid_Result = '+' , float _answer = 2.36 , int number3 = 54 ,float we_got_final_answer_with_solution = 66.59 ,char ikoo = '&' .
- In above examples price, Covid_Result ,_answer ,number3, we_got_final_answer_with_solution are variables with valid names sine they are following correct rules.
- We can create length of variables as much as we can more than 1 character .
- Suggestion : Please do avoid meaningless and large conventions because they may look like confusing and disturbing in large codes it may effect your future purposes .
- As we seen above ikoo and we_got_final_answer_with_solution are correct naming convention but they are not advisable because they may look are create some mess in our large codes
- So guys try to use small and meaningful names .
- Here are some wrong examples to select variables
- int 5price = 32 => here it is wrong because variable started with number
- char Covid Result = '+' => here it is wrong because variable contain space between Covid and Result
- float #answer = 2.36 here it is wrong because variable contain special character .
- float void = 6.55 => here it is wrong because we used reserved word as variable
***** If you have any doubts please ask in comment box*****
thank you .
I don't get this. It's not clear
ReplyDeletePlease read lecture 1 and lecture 2 then you an understand the things
Delete