As already known character known character range is between -128 to 127 or 0 to 255. This point has to be kept in mind while doing character arithmetic. To understand better let’s take an example.
So %d specifier causes an integer value to be printed and %c specifier causes a character value to printed. But care has to taken that while using %c specifier the integer value should not exceed 127.
So far so good.
But for c++ it plays out a little different.
Look at this example to understand better.
A 65 a
Without a ‘+’ operator character value is printed. But when used along with ‘+’ operator behaved differently. Use of ‘+’ operator implicitly typecasts it to an ‘int’. So to conclude, in character arithmetic, typecasting of char variable to ‘char’ is explicit and to ‘int’ it is implicit.
This article is contributed by Parveen Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check input character is alphabet, digit or special character
- Sum of array using pointer arithmetic
- How to sum two integers without using arithmetic operators in C/C++?
- Multidimensional Pointer Arithmetic in C/C++
- Ratio Manipulations in C++ | Set 1 (Arithmetic)
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Conditionally assign a value without using conditional and arithmetic operators
- Character Classification in C++ : cctype
- Data type of character constants in C and C++
- Type difference of character literals in C and C++
- Change/add only one character and print '*' exactly 20 times
- Differentiate printable and control character in C ?
- getline() function and character array
- Frequency of each character in a String using unordered_map in C++
- Convert character array to string in C++
- How to convert a single character to string in C++?
- Storage of integer and character values in C
- Program to count occurrence of a given character in a string
- Print a character n times without using loop, recursion or goto in C++