- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
Advertisements