So I'm trying to print a table of characters with their corresponding integer values. Below is my code:-
#include <iostream>
using namespace std;
int main()
{
char i = 'a';
while (i <= 'z')
{
cout << i << '\t' << 'a' + 1 << '\n';
++i;
}
}
I tried to put char('a' + 1) in the code which gave me a whole lot of wrong answers.
Output(correct output) I get by using static_cast in code:- a 97 b 98 c 99 .... z 122
Output I'm getting using the above written code:- a 98 b 98 ..... z 98
So i would like to know what is the difference between char('a'+1) and 'a' + 1 and static_cast(i)?