C Token

In this tutorial, we will learn about C token and types of tokens in C. 

C tokens are the smallest individual unit or building block of a program that conveys special meaning to the language compiler. Tokens are also known as Lexical Units. 

C Tokens and its types in C Programming
C Tokens

Types of Tokens in C

  1. Keywords
  2. Identifiers
  3. Constants
  4. Operators
  5. Strings
  6. Special Symbols

Keywords in C

Keywords are reserved words having a special meaning in the programming language. These c tokens Keywords are pre-defined words in a programming language that convey a special meaning to the compiler. 

C language supports 32 keywords. C keywords classification which is given below



auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while

Identifiers in C

The identifier is a fundamental building block and is used as the general terminology for names given to different parts of programs are variables, arrays, and functions. 

Rules for naming identifiers

  • The first character must be Letter(A-Z or a-z) or Underscore(_).
  • You can not use any special symbol in identifier i.e. @,+,-,., etc.
  • You can not use keywords as identifiers.
  • It should not contain any space between them.
  • In the same program, two or more same identifiers are not possible.

Some examples of c identifiers are


_file            Valid
MY.DOB     invalid because it contains a special symbol dot(.)


Constants in C

Constants refer to fixed values. Constants are like any other normal variables of the program but the only difference is once you defined than their data items( values ) that never change or modify their value during execution of a program. These are also known as Literals.

Following are the various types of constants

  1. Integer Constants
  2. Character Constants
  3. Floating Constants
  4. String constants

Operators in C

Operators are that are trigger some calculus when applied to variables in an expression. Operators are acts on operands (Operands are data items on which operators act.)

C tokens Operators are classified on the basis of the number of operands are

  • Unary Operators: These are operators those required one operand to operates. 
   Some unary operators are followed:
       ++ increment 
       -- decrement, etc.

  • Binary Operators: These are operators that required two operands to operates on it.
 Some Binary Operators are followed:

  1. Arithmetic operators
  2. Assignment Operators
  3. Bitwise Operators
  4. Conditional Operators
  5. Logical Operators
  6. Relational Operator

String in C

A string token is a character array that ended with a null character (‘\0’). Null character shows the end of the character array. Strings are always enclosed in double quotes(“”) and character is enclosed by single quotes(‘’).

Examples
char string[20] = “codeamy”; \\ In this 20 bytes of memory space is allocated by programmers to holding the string.
(or)
char string [] = “codeamy”; \\ In this memory space is allocated by the compiler at the time of execution.
(or)
char string[20] = {‘c’, ’o’, ‘d’, ‘e’, ‘a’, ‘m’, ‘y’, ‘\0’};

Special Symbols in C Tokens

C tokens have special symbols used that have special meanings that cannot be used for another purpose. 
  1. Asterisk (*)
  2. Assignment operator
  3. Curly Braces { }
  4. Comma (,)
  5. Parentheses ( )
  6. Preprocessor (#)
  7. Square Brackets [ ]
  8. Semicolon (;)
In the above article on C tokens and types of tokens in C, If you have any doubt and also share your experience in the comment box below. 

No comments:

If you have any doubts, Please let me know

Powered by Blogger.