C Tokens - Keywords, Identifiers in c, different and how many types

In this tutorial, we will learn about c tokens that contain keywords, identifiers, constants, operators, strings and special symbols. Also, below you learn each classification in detail.

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

Tokens in C
Tokens in C

various types of c tokens

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

Different types of c tokens

Keywords in c

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


Detail Description on C keywords ClickHere
C language supports 32 keywords which are 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

More on C keywords ClickHere

Identifiers in c

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. 


 Detail Description on C Identifiers ClickHere

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(.)

More Examples on C IdentifierClickHere

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
For more on the individual type of constants clickhere

Operators in c 

Operators are tokens 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 Operators are classified on the basis of the number of operands are:

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

  • Binary Operators: Binary operators 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 

String 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

Special symbols are symbols used that have special meanings that cannot be used for another purpose.

Following special symbols

  1. Asterisk (*)
  2. Assignment operator
  3. Curly Braces { }
  4. Comma (,)
  5. Parentheses ( )
  6. Preprocessor (#)
  7. Square Brackets [ ]
  8. Semicolon (;)

   Above article on tokens in c, If you have any doubt and also share
your experience in comment box below.

Share this

0 Comment to "C Tokens - Keywords, Identifiers in c, different and how many types"

Post a Comment