# (char)09 not valid?

This is a discussion on (char)09 not valid? within the C++ Programming forums, part of the General Programming Boards category; ok, if I do the following, I get the following: for some reason the compiler thinks that 08 and 09 ...

1. ## (char)09 not valid?

ok, if I do the following, I get the following:
for some reason the compiler thinks that 08 and 09 are octal values. Anything decimal 10+ is fine.

Code:
```outp<<(char)09

gives

invalid digit "9" in octal constant|```
How do I tell the compiler it's a decimal?

If I do this, it is fine!
Code:
```int main()
{
for ( int x = 0; x < 20; x++ ) {
cout<< x <<": "<< (char)x <<"\n";
//Note the use of the int version of x to
// output a number and the use of (char) to
// typecast the x into a character
// which outputs the ASCII character that
// corresponds to the current number
}
cin.get();
return 0;
}```

2. How do I tell the compiler it's a decimal?
Code:
`outp << (char) 9;`
The reason compiler "thinks" they are octal is because literals beginning with a leading 0 are octal, like literals beginning with 0x are hex.

3. ah cool, thank you, I wonder if this point could be added to the C++ tutorial on typecasting?

4. Originally Posted by mikeyp
ah cool, thank you, I wonder if this point could be added to the C++ tutorial on typecasting?
It has nothing to do with typecasting. The compiler would complain the same way if the cast had not been there.

5. Originally Posted by brewbuck
It has nothing to do with typecasting. The compiler would complain the same way if the cast had not been there.
I know I'm new to C++ programming but can you explain what you mean? My request to have it included in the tutorial is based on the below, where I got my code for the char conversion from.

Cprogramming.com Tutorial: Typecasting
Second code example down... the tutorial needs the different types of code (dec, oct, hex) explaining to save confusion in the future.

My point was that this tutorial would be a good time to explain this.

6. Typecasting has little to do with how compilers parse literals.

We usually write 9 as 9 and not 09.