When reading my book i look at the following abbreviated example and ask when the program is checking the data type *char* in this example it can determine if a letter is greater or equal to 'A' and also less or equal to 'Z' however since they are non numeric how does it know that 'A' is less than 'Z'. When a variable is defined as *char* does it essentially break the variable defined as *char* into hex code and evaluate it from the hex codes which are numerical or am i missing something?
Every ASCII character has a decimal/hex value.
So when you do a comparison with a char it uses that number.
If you want to see the values they are run this program:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main ()
{
for (char ch = 'A'; ch <= 'Z'; ++ch) // This works because chars are byte sized integers.
std::cout << ch << " : " << (int)ch << '\n';
std::cout << "\n\n";
for (char ch = 'a'; ch <= 'z'; ++ch) // This works because chars are byte sized integers.
std::cout << ch << " : " << (int)ch << '\n';
return 0;
}
$ ./charasdec.exe
A : 65
B : 66
C : 67
D : 68
E : 69
F : 70
G : 71
H : 72
I : 73
J : 74
K : 75
L : 76
M : 77
N : 78
O : 79
P : 80
Q : 81
R : 82
S : 83
T : 84
U : 85
V : 86
W : 87
X : 88
Y : 89
Z : 90
a : 97
b : 98
c : 99
d : 100
e : 101
f : 102
g : 103
h : 104
i : 105
j : 106
k : 107
l : 108
m : 109
n : 110
o : 111
p : 112
q : 113
r : 114
s : 115
t : 116
u : 117
v : 118
w : 119
x : 120
y : 121
z : 122
I also have to ask is it coincidence that the upper-case and lower-case are exactly 32 characters apart, Or done specifically for this convenience. Seems that it would be somewhat easy to subtract or add the two to convert between them