# Have a really basic easy question..

• 03-01-2005
weezer562
Have a really basic easy question..
im trying to get ready for my test tommorow. And well giong over my old labs....I came to this..
I have these to function defs....

Code:

```void CharSet::Add(char Value) {   Contents[Value - 'A'] = true; } void CharSet::Remove(char Value) {   Contents[Value - 'A'] = false;```
And Although I used it I never fully understood....the Value -'A'...I was wondering if someone could help me out and give me an explanation into how it is used....I really don't recall using that or being taught that. I used it because the teacher in his instructions hinted for us to use it.
• 03-01-2005
pianorain
Assuming that Value holds an uppercase character, the expression Value - 'A' would give you a zero-based index of the uppercase letters, with 'A' being 0 and 'Z' being 25.
• 03-01-2005
The Brain
The contents of 'A' is the ascii value for the upper-case A... in this case, 'A' is being used as a numeric constant (in hex: 40h in dec: 64d)
• 03-01-2005
weezer562
...
oh ok i see....makes more sense now....thanks for the help...
• 03-01-2005
7stud
Another take: characters are stored internally as integer codes. An ASCII table will show you the list of integer codes. Since they are integers, you can do mathematical operations on them:
Code:

```char ch = 'A'; ch += 2; cout<<ch<<endl;  //C```
When you output a char type, C++ converts the interger code back to a character. So, if you actually want to output the integer code, then you have to convert a char type to an integer:
Code:

```char ch = 'A'; int code = ch; cout<<code<<endl; //65 cout<<ch<<endl;  //A```
It better style to make an explicit cast, instead, in order to demonstrate that's what you intended:
Code:

```char ch = 'A'; int code = static_cast<int>(ch); cout<<code<<endl; //65```
• 03-01-2005
7stud
Another take: characters are stored internally as integer codes. An ASCII table will show you the list of integer codes. Since they are integers, you can do mathematical operations on them:
Code:

```char ch = 'A'; ch += 2; cout<<ch<<endl;  //C```
When you output a char type, C++ converts the interger code back to a character. So, if you actually want to output the integer code, then you have to convert a char type to an integer:
Code:

```char ch = 'A'; int code = ch; cout<<code<<endl; //65 cout<<ch<<endl;  //A```
It's better style to make an explicit cast, instead, in order to demonstrate that's what you intended:
Code:

```char ch = 'A'; int code = static_cast<int>(ch); cout<<code<<endl; //65```
Good luck on your test. :)
Tests :(