Quick Contact


    C Tokens and Literals

    C language is the server-side programming language, and tokens are the smallest element of a particular program or code. The tokens are very meaningful to the compiler at the compilation and execution time of the code.

    C Tokens and Literals

    There are some special types of tokens, which are given below:

    • Keywords as C token

      The keywords are the predefined words in C programming language with specific features and help everyone to use the functionality of the particular language.

    • Strings

      The string is the array of character which ended with the null character, and that null character indicates the ending point of any string. When we use strings in the program, then all the strings are enclosed with double quotes (“”), and some examples of string declaration are given below:

      • char string [19] = {‘a’,’b’, ‘c’,’\0’};
      • char string [22] = “student”;
    • Identifiers as the Token of C language

      The identifier is related to every program element in the C language, which is mainly used for naming the variables, functions, and arrays. These names are user-defined, which consists of alphabets, numbers, underscores etc., and the name of any identifier should never be similar to the keyword name because the keywords are never used as the identifier in the particular program.

    • Constants

      The constants are related to the particular program’s fixed values, which may not be changed during the execution time. The constants are also known as the literals in a particular program or code.

    • Special Characters

      The special characters are beginning with the letter or underscore in any code or program. Any special character should not be any keyword in the C language.

    Literals in C Programming Language

    The literals are the constant or fixed values in the program, and these values cannot be altered in the entire procedure.

    Types of Literals in C programming language
    C Tokens and Literals

    Figure: Types of Literals in C language.

    There are four types of literals in C language, which are given below:

    • Integer Literals in C

      The integer literals are the numeric literals that can represent only numeric or integer type values in the C program.

    • Example:
      			#include < stdio.h>
      			int main ()  
      			{  
      			    const int a=92;  
      			    printf ("Integer literal: %d", a);  
      			    return 0;  
      			}    
      		
      Output:

      Integer literal: 92

    • C programming Floating-point literals

      The float literal or constants are related to the floating-point values in the program. These kinds of literals can hold the integer part, real part, exponential and fractional part of a particular number.

    • o String Literals in C

      The string literals can represent various characters, which are enclosed with the double quotes in the code. These types of literals can hold additional characters that are automatically inserted.

    • o Character literals in C language

      The character literals represent a single character enclosed with single quotes in C programming language. When the user needs to create the character array, then several characters are assigned to the variable within the program.

    • Example:
      			#include < stdio.h>
      			int main () 
      			{
      			   const char charVal = 'Z'; 
      			   printf ("Character Literal: %c\n",charVal); 
      			   return 0;
      			}   
      		
      Output:

      Character Literal: Z

    Copyright 1999- Ducat Creative, All rights reserved.