![]() |
Character arithmetic in C++ involves performing mathematical operations on characters. In C++, characters are represented using the char data type, which is essentially an integer type that stores ASCII values. In this article, we will discuss character arithmetic and how to perform character arithmetic in C++. What is Character Arithmetic in C++?Character arithmetic involves performing arithmetic operations on characters based on their ASCII values. So when some operations are performed on the characters, they are automatically promoted to integers. This process is called integer promotion. Due to this, we can perform some common mathematical operations on the character type variables. Following are some common character arithmetic operations:
Example of Character Arithmetic in C++The below example demonstrates the common arithmetic operations on characters. C++
Output
Original character: A After increment (++): B After decrement (--): A After adding 3: D After subtracting 2: B ConclusionCharacter arithmetic in C++ provides a way to manipulate characters through their ASCII values. This knowledge is particularly useful in scenarios where characters need to be transformed, encrypted, or manipulated in various ways. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |