Avatar ·

How to convert char to int in C and C++? Understanding digits and characters

Hello everyone! I just started learning C++ and encountered a confusing situation. I need to read a character from standard input and convert it to an integer to perform arithmetic operations with it. Here's my C++ code:\n\n```cpp\n#include \nusing namespace std;\n\nint main() {\n char c;\n cout << "Enter a digit: ";\n cin >> c;\n int num = (int)c; // Trying to convert char to int\n cout << "The entered number multiplied by 2: " << num * 2 << endl;\n return 0;\n}\n```\n\nIf I enter `5`, I expect to get `10` as output, but the program outputs `106`! Why is that? I read that `char` is an integer type and can be cast to `int`. But apparently, I'm doing something wrong. Tell me how to correctly convert a character containing a digit into an integer? And what is the general