Character arithmetic in C


Character arithmetic is used to implement arithmetic operations like addition and subtraction on characters in C language. It is used to manipulate the strings. When the characters are used with the arithmetic operations, it converts them into integer value automatically i.e. ASCII value of characters.

Here is an example of character arithmetic in C language,

Example

 Live Demo

#include <stdio.h>

int main(){
   char s = 'm';
   char t = 'z' - 'y';

   printf("%d\n", s);
   printf("%c\n", s);
   printf("%d\n", (s+1));
   printf("%c\n", (s+1));
   printf("%d\n", (s-1));
   printf("%c\n", (s-1));
   printf("%d\n", t);
   // printf("%c", t);

   return 0;
}

Output

Here is the output −

109
m
110
n
108
l
1

Updated on: 25-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements