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 email@example.com. 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.
- Is there any need of "long" data type in C and C++?
- What is size_t data type in C language?
- Interesting facts about data-types and modifiers in C/C++
- Difference between float and double in C/C++
- std::find in C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Type Conversion in C
- Operators in C | Set 1 (Arithmetic Operators)
- Storage Classes in C
- Static Variables in C
- Data Types in C
- Integer Promotions in C
- How to Count Variable Numbers of Arguments in C?
- Return values of printf() and scanf() in C/C++
- Understanding "extern" keyword in C