Identifiers are like Nicknames
Imagine you have a pet cat, and you call it "Whiskers." "Whiskers" is like a nickname, right? In C language, identifiers are a bit like nicknames for things in your program. They help you remember and talk about different parts of your code.
Rules for Identifiers as follow:
Names for Things:
Identifiers are like names for different things in your program. It could be a variable, a function, or anything else you want to talk about.
Start with a Letter or Underscore:
Identifiers can start with a letter (like 'cat') or an underscore ('_'). They can't start with a number.
Can Have Letters and Numbers:
After the first letter, you can use letters or numbers. For example, 'cat123' is a valid identifier.
No Spaces or Special Characters:
You can't have spaces or special characters (except for the underscore) in identifiers.
So, 'my cat' wouldn't work, but 'my_cat' is fine.
Case Sensitive:
C is picky about capitalization. 'Cat' and 'cat' would be treated as different identifiers. So, be consistent!
Avoid Keywords:
Don't use words that C already uses for special things (like 'if' or 'int'). Those are reserved, and C already knows what they mean.
Examples of Identifiers:
Let's say you want to store the age of your cat and the number of whiskers it has. You could use identifiers like this:
int catAge; // 'catAge' is an identifier for the age of your cat
int numWhiskers; // 'numWhiskers' is an identifier for the number of whiskers
These identifiers help you keep track of what each variable is for.
Why Identifiers Matter:
Identifiers make your program readable and understandable. Just like calling your cat "Whiskers" makes it easier to talk about, using good identifiers makes your code clear and easy to work with. So, when you see 'catAge' in your code, you know it's all about your cat's age!
Remember, identifiers are like the nicknames you give to things in your program, and they play a big role in making your code friendly and easy to manage!
0 Comments
If you have any doubts, Please let me know