Tokens in C language | Types of Tokens In C Language [Updated]

When you learn a new language, then you learn first about the basic things of that language because without basic information you cannot understand the rest of the things.

In the same way, before learning C language, today we are going to talking about some basics such as – Tokens, keywords, identifiers, etc.

Today we will learn in detail about What is tokens in C and what are the types of tokens in C?

So let’s start to know about tokens In C

Tokens in C language | Types of Tokens In C Language
Tokens in C language | Types of Tokens In C Language

Tokens in C language

When we write a program in the C language, then there are some statements in the program and every statement has some words and every word has some meaning. In easy words, we divide the program into many small units, the smallest unit of these programs is called Tokens.

Token is the smallest unit of C language that is most commonly used to build a program in C language.

Let’s understand this with an example -:

when we write a sentence in English, then Sentence is made up of many words and every Word has some meaning. Just like we cannot create a Sentence without using Word. In the same way in C language we cannot create a program without using tokens because tokens are the smallest unit of C language which is very important to build a program.

Types of Tokens In C

There are six types of tokens –

  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Special Symbols
  • Operators

Let’s learn one by one about all these types of C Tokens in detail.

1. Keywords

When we write a program in C language, then there are some words in the program and every word has some meaning, and the word which is already defined is called Keyword or Reserved Word or Predefined Word.

Because the keywords are predefined or reserved, so they cannot be used as the name of a variable. They have their own different significance and specialty.

If we use a keyword as the name of a Variable, then it means, we are changing the meaning of the keyword which is not allowed in the C language.

Each keyword has its own meaning, and its meaning cannot be changed. The compiler is already aware of the meaning of all keywords, so the compiler does not need to tell the meaning of these keywords separately.

C language supports total 32 keywords, which are given below. We write the keywords in the lowercase letter.

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constshortfloatunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile
Keywords In C

2. Identifiers

You will see many things in your daily life such as car, mobile, home, your friends like Ramesh, Suresh, etc. You may know all of them by a different name. Just think once, if they are not named, how will you talk about them? 

So it is very important to have their name so that we can uniquely identify everyone and that name we call Identifiers.

Identifiers are used to name Variable, Function, Array, Structure, etc. In C language, Identifiers are user-defined. User-defined means the user determines what will be the name of Variable, Function, Array, Structure, etc.

The names contain only uppercase letters, lowercase letters, underscore, and numbers. But the two identifiers cannot have the same name. Also, we cannot use keywords as identifiers.

Some rules for making identifiers:

  • The first letter of the identifier will be the alphabet, and the underscore.
  • Only uppercase letters, lowercase letters, underscore, and numbers can be used in this.
  • In the Identifier name white space is not allowed.
  • A keyword cannot be used as an identifier.
  • Identifiers may not exceed 31 characters in length.
  • Whatever Identifiers you make should be Meaningful.
  • Identifiers’ names cannot begin with numbers.

3. String

String is an Array of character that ends with a Null character (\ 0). The Null character (\ 0) indicates that the string is over. String is always written with double quotes (” “). The size of the string depends on the number of characters present in it.

We can define a string in different ways -:

  • char string [20] = {‘C’, ‘s’, T’, ‘u’, ‘t’, ‘o’, r ‘, i’, ‘a’, ‘l’, p ‘, o’, ‘i’, ‘n’, ‘t’, ‘\ 0’};
  • char string [20] = “CsTutorialpoint”;
  • char string [] = “CsTutorialpoint”;

In the above examples, the compiler will allocate 20 bytes of memory in the string, in which String is represented as a character. In the second example also, the compiler will allocate 20 bytes of memory to the string in RAM, and in the third example, the compiler will allocate memory to the string in RAM at run time.

4. Operator

You must have read about a lot of operators in maths. For example, like 2 + 4 in it, 2 and 4 are called operands or data, and + we are called operators. So the operator performs the basic operation and the operator needs some data or operands for the operation. Without operands, the operator cannot do any of his work.

In C language, there are some similar operators, with the help of which we perform some operations. Depending on the number of operands the operator can be divided into two parts: –

  1. Unary Operators
  2. Binary Operators

#1. Unary Operators

The operators who need only one operand to perform the operation are called Unary Operators. For example, in the increment and decrement operator, only one of the operands is required to perform the operation. Increment operator (++), decrement operator (-) and sizeof, (type) * etc. are Unary Operator.

#2. Binary Operators

Operators who need more than one operand to perform an operation are called Binary Operators.

Binary Operators are of the following types:

  • Arithmetic operators
  • Relational Operators
  • Logical Operators
  • Assignment Operators
  • Conditional Operators
  • Bitwise operators

Click here to read in detail about Operators 👉 Operators In C

5. Constant

Constants are those whose value does not change. Once the value is declared, it cannot be changed. Constant’s value is fixed, this is also called Literals.

We can declare Constant in two ways -:

  • Using const keyword
  • Using #define pre-processor

Types of Constant

ConstantExample
Integer constant4, 111, 110, 34, etc.
Floating-point constant65.6, 67.8, 11.2, 2.0 etc.
Octal constant011, 088, 022, etc.
Hexadecimal constant0x1a, 0x4b, 0x6b, etc.
Character constant‘a’, ‘b’, ‘c’, etc.
String constant“C”, “C++”, “Python”, “Java”, “.net”, etc.

Click here to read in detail about Constant 👉 Constant In C

6. Special Character

Some special symbols are used in C language which has their own special meaning and cannot be used for any other purpose.

The following Special Symbols are used in the C language which has their own special meaning and cannot be used for any other purpose.

Brackets [] -: Opening and Closing brackets are used in references to the Array element, It also indicate single and multidimensional subscripts.

Parentheses () -: parenthesis () is used in function calls and function declaration in C language.

Curly Braces {} -: Curly Braces {} is used to start and end the code. Curly Braces {} tells the compiler that the code starts where it is and ends with it.

Comma (,) -: Comma (,) is used to separate multiple statements such as when separating parameters in a function call, when printing the value of more than one variable by printf(). To isolate those variables, etc. 

Semicolon (;) -: The semicolon (;) is used when a statement in the program has ended. the semicolon tells the compiler that the statement in the program has ended.

Assignment operator (=) -: It is used to assign value to a variable in C language.

Pre-processor (#) -: This is used for preprocessor directives. This symbol tells the pre-processor, that the header file is to be used in this line of the program.

By this time you must have understood what are tokens and what are the types of tokens In C Language.

Well, today in this article I have used some words (such as Variable, Function, Array, Structure, etc.), so you may have some difficulty to understanding them because you do not know the meaning of them.

Because you are just starting to learn the language, you will have some problems to understanding the meaning of some words. But as you study further everything will become clear.

By the way, I am giving the link of all these, from where you can read about them (Variable, Function, Array, Structure, etc.) and get some idea about them.

Conclusion

Friends, I hope you have found the answer to your question and you will not have to search about the c tokens

However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts 

If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.

Friends, if you liked this post, then definitely share this post with your friends so that they can get information about The tokens in c language

To get the information related to Programming Language, Coding, C, C ++, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

2 thoughts on “Tokens in C language | Types of Tokens In C Language [Updated]”

Leave a Comment