Keywords And Idnetifiers In C

Posted on October 19, 2023 by Vishesh Namdev
Python C C++ Javascript Java
C Programming Language

Keywords in C programming are like special words that have predefined meanings. You can think of them as the building blocks of the language. These words are reserved and used for specific tasks within the C programming language. They cannot be used for naming variables, functions, or other things in your program because they already have a job to do.

int royal ;

For example, words like "int," "if," "while," and "return" are keywords in C. When you use "int," you're telling the computer that you're going to work with integers. When you use "if," you're telling the computer to make a decision based on a condition. These words are like a secret code that the computer understands, and you can't change their meanings.

So, in simple terms, keywords in C are special words that have specific jobs in the C language, and you can't use them for anything else in your code.

difference between C and C++

Identifiers

Identifiers in C are like names for program elements such as variables, functions, and structures. They need to be unique to distinguish these elements within the code. Identifiers make code readable and help programmers locate and work with specific components efficiently.

int age ; Copy Code
long phone_number ;
double balance ;

In this example, int , phone_number , balance are Idnetifiers
It's essential to note that identifiers must have unique names distinct from reserved keywords. For instance, you can't name a variable "int" since "int" is a reserved keyword in C.

The rules for naming identifiers in C are as follows:

1. Character Set: Identifiers can consist of letters (both uppercase and lowercase), digits, and underscores. Special characters and spaces are not allowed.

2. First Character: The first character of an identifier must be a letter (A-Z or a-z) or an underscore (_).

3. Case Sensitivity: C is case-sensitive, so uppercase and lowercase letters are treated as distinct. For example, "myVariable" and "myvariable" are different identifiers.

4. Keywords : Identifiers cannot have the same name as C keywords (reserved words), such as int, while, and for. These keywords have predefined meanings in the language.

5. Length Limit: There is no strict limit on the length of an identifier in the C standard. However, some compilers may impose their own length limits, typically around 31 characters.

6. Meaningful Names: It's a good practice to use descriptive and meaningful names for identifiers to enhance code readability. For example, using "counter" instead of a cryptic name like "c."

In summary, identifiers in C must follow a set of rules regarding character set, the first character, case sensitivity, avoidance of keywords, and meaningful naming practices to ensure proper functionality and readability in your code.