Why 97?

Why is the output 97 for a, 98 for b and so on?

1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

int main(){
int a = 'a';
int b = 'b';
cout << a << endl << b ;

}
Last edited on
You are assigning the variable as int, but giving it a CHAR value.
a is ascii code 97 I do believe.
Because the ascii code for a = 97 and the code for b = 98. Look an ascii table and look at a and b. If you want the console to print out the characters 'a' and 'b' then you need to assign them to a variable as a char (not an int).
Ok so why there is no ASCII code for "a" if 'a' and "a" both are character?
Last edited on
inside double quotes "a" is a string. Inside single quotes 'a' it is a char. Strings and chars are different in that a string is a bunch of chars (Characters) "Strung" together... It's a different process.
Last edited on
Topic archived. No new replies allowed.