Keywords and Identifiers in C

Keywords and Identifiers in C

In this article, we are going to learn about keywords and identifiers in C. These are two very basic, but very important concepts when you are learning C programming language. Also, once you are familiar with these concepts, you would be more comfortable in writing C programs.

Keywords and Identifiers in C

Difference Between Keywords and Identifiers in C

Keywords in C

Well, The keywords are the reserved words, or you can say these are some words, whose meaning is already understood by the compiler. We can say that the keywords are used only where they are supposed to be used. For example, let’s say that there is a toolbox with a lot of tools in it, which are used to build a house. Each tool in the toolbox is used for some particular purpose. It is like each tool has its existence for something in particular. We can understand in other words, that the keywords in programming are supposed to be used in certain contexts only.

32 Keywords in C

So, in C language in general, there are a total of 32 keywords. Don’t worry, you don’t have to remember the keywords. As we will move ahead, we will use the keywords as and when required.

autobreakcasechar
constcontinuedefaultdo
doubleelseenumextern
floatforgotoif
intlongregisterreturn
shortsignedsize ofstatic
structswitchtypedefunion
unsignedvoidvolatilewhile

As can be seen from the above table, we have listed all the keywords in C programming language, so that you can have them in one place as and when required. Honestly, you do not have to remember these keywords. No one would really ask you to recite all the keywords. When you would perform more and more programs, you would use different keywords in your program, and you would gradually get familiar with them, and be comfortable using them in your programs.

For example, the keywords like for, while, do would be used in looping. On the other hand, int, float, and char would be used when we create variables. So, these keywords are just supposed to be used in some particular context.

Later on, when you would perform more and more programs, in that, you would use different keywords, which would be used for different purposes. So then, you would really become familiar with the keywords, and be comfortable in using them.

Identifiers in C

Well, identifiers are just the names given to the variables, functions, etc. (something that is user-defined). This is done to access and identify the different things like variables, functions, etc. We will be learning about variables, functions, etc. ahead, so don’t worry about these concepts. Just understand that variables are used to store some data, and the functions are some blocks of code, that will do some specific task.

There are some rules for setting identifiers →

  • You cannot use keyword names for identifiers.
  • It has to start with an alphabet(lowercase or uppercase), or an underscore( _ ).
  • The identifier can contain digits, but not at the start.
  • The characters like @, $, and % are not allowed.
  • Whitespaces are not allowed in the name.
  • C language is case-sensitive. So, if you name a variable as a number, and another variable as a Number, both are different things.

Here are examples of some correct and some incorrect identifiers →

The correct identifiers →

  • number
  • sumcalculator
  • mysum
  • variable_1
  • company_name
    and many more…

The incorrect identifiers →

  • 1number
  • if
  • else
  • while
  • for
  • 8company
    and many more…

So, as you can see from the above examples, we have some valid variable names and some invalid variable names. You also do not really need to remember the rules. Once you began writing C programs and began naming the functions, variables, etc. you would gradually become familiar with the rules.

Summary

In this article, we had a look at keywords in C and also learned about identifiers in C language. Keywords are very important in our C programs, and from time to time in your programs, you would use different keywords for some specific purposes.

Later on, when you would perform many different programs, you would become familiar with the concept of keywords, and the identifiers as well.

FAQs based on Keywords and Identifiers in C

Q: What are Keywords in C?

Ans: Keywords or reserved words can be considered as some words, which have specific meanings, and can be used for some specific purposes only, and not anywhere else.

Q: How many Keywords are there in C?

Ans: In general, there are 32 keywords in the C language.

Q: What are identifiers in C?

Ans: You can understand the identifiers as names given to some variables, functions, etc. in order to identify them.