Literals are the constant values assign to the constant variables. The Literals represent the fixed values that cannot be modifies. It also contains memory but does not have references as variables is knows as C Literals.

Types of literals

There are four types of C literals.

  • Integer literal
  • Character literal
  • Float literal
  • String literal

Integer literal

It is a numeric literal that represents only integer type values. It represents the value neither in fractional nor exponential part is knows as Integer literal.

Types

Integer literal are the following three ways:-

  • Decimal Number
  • Octal Number
  • HexaDecimal Number

Decimal Number

It is define by representing the digits between 0 to 9 is knows as Decimal Number.

Octal Number

It is define as a number in which 0 is followed by digits such as 0,1,2,3,4,5,6,7 is knows as Octal Number.

HexaDecimal Number

It is define as a number in which 0x or 0X is follows by the hexadecimal digits is knows as HexaDecimal Number.

An integer literal is Suffix by following two sign

L or l: It is a size qualifier that represents the size of the integer type as long.

U or u: It is a sign qualifier that represents the type of the integer as unsigned. Unsigned qualifier contains only positive values.

Example of Integer literal

#include <stdio.h>  
int main()  
{  
    const int x=250;
    printf("Integer literal : %d", x);  
    return 0;  
}  

Output of Integer literal

Output value

Float literal

It is a literal that contains only floating-point values or real numbers is knows as Float literal.

Example of Float literal

#include <stdio.h>  
int main()  
{  
    const float x=11.5;
    const float y=51.6;  
    float sum;  
    sum=x+y;  
    printf("%f", sum);  
    return 0;  
}  

Output of Float literal

Output value

Character literal

A character literal contains a single character enclosed within single quotes is knows as Character literal.

Example of Character literal

#include <stdio.h>  
int main()  
{  
    const char r='b';  
    printf("%c",r);  
    return 0;  
}  

Output of Character literal

Output value

Token

Tokens are the smallest elements of a program, which are meaningful to the compiler is knows as Tokens

Classification of tokens in C programming language

  • Keywords
  • Strings
  • Identifiers
  • Operators
  • Special Characters
  • Constant

Keywords

Keywords are predefine and reserve words in C and each of which is associates with specific features. There are total 32 keywords in C.

autostructdoubleint
breakelselongswitch
caseregisterenumtypedef
charexternreturnunion
continueforvoidsigned
doifstaticwhile
defaultgotosizeofvolatile
constfloatshortunsigned

Identifier

An identifier is use for any variable, constants, functions, structures, pointers, arrays, structures, unions, labels, or any other user-define data, to identify them. An identifier can be compose of letters just like uppercase, lowercase letters, underscore, digits. The starting letter should be either an alphabet or an underscore only. It can not start with a digit. There are 52 alphabetical characters (uppercase and lowercase), underscore character, and 10 numerical digits (0-9) that represent the identifiers. There is a total of 63 alphanumerical characters that represent the identifiers is knows as C Identifier.

Strings

A string is an array of characters ended with a null character is knows as String. Strings are always enclosed with double quotes(“ “).

Example of String

#include <stdio.h>
int main() {
   // using keyword char 
   char a1 = 'R';   
   int b = 5;     
   float d = 1.8;
  
   char string[200] = "basic";   
    
   if(b<10)    
      printf("Character Value : %c\n",a1);
   else
      printf("Float value : %f\n",d);
      printf("String Value : %s\n", string);
   return 0;
}

Output of string

Output value

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about C Programming language please Wikipedia click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *