C Programming/Tokens: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
(Created page with "== C Tokens == C Supports Six Types of Tokens: # Identifiers # Keywords # Constants # Strings # Op...")
 
Line 3: Line 3:
# [[C_Programming/C_Tokens#Identifiers |Identifiers ]]
# [[C_Programming/C_Tokens#Identifiers |Identifiers ]]
# [[C_Programming/C_Tokens#Keywords|Keywords]]
# [[C_Programming/C_Tokens#Keywords|Keywords]]
# Constants
# [[C_Programming/C_Tokens#Constants |Constants ]]
# Strings
# Strings
# Operators
# Operators
Line 43: Line 43:
| do || if || static || while
| do || if || static || while
|}
|}
=== Constant ===
A constant is an identifier whose value cannot be altered in a program. For example: 1, 2.5, "C programming is easy", etc.


== Differentiate ==
== Differentiate ==

Revision as of 02:48, 5 February 2018

C Tokens

C Supports Six Types of Tokens:

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

Identifiers

Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore.

Rules for Naming Identifiers:

  1. An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
  2. Identifier names must be unique
  3. The first character must be an alphabet or underscore.
  4. Cannot be keyword as identifiers.
  5. Should not be of length more than 31 characters.
  6. Must not contain white spaces.
  7. Identifiers are case-sensitive.

Kinds of identifiers:

  1. Internal
  2. External

Keywords

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

Constant

A constant is an identifier whose value cannot be altered in a program. For example: 1, 2.5, "C programming is easy", etc.

Differentiate

Keywords vs Identifiers

Keyword Identifier
Predefined-word User-defined word
Must be written in lowercase only Can written in lowercase and uppercase
Has fixed meaning Must be meaningful in the program
Whose meaning has already been explained to the C compiler Whose meaning not explained to the C compiler
Combination of alphabetic characters Combination of alphanumeric characters
Used only for it intended purpose Used for required purpose
Underscore character is not considered as a letter Underscore character is considered as a letter