![]() |
Char assignment using Octal values
Hi,
I'd like to know why assigning a value to char using an octal value sometimes gives a warning message causing incorrect output. Please look at the following code: :
int main(void)Here c is assigned the character "<" but d gives a warning on compile and will be displayed as the character "1" where as e displays "A". I don't understand why I can have a leading 0 inconjunction with the "\" character sometimes and not other times. I could just assign the values with leading zeroes and take away the "\" and single quotes but I'd just like to understand my problem to better understand C. |
An ASCII character in octal notation may only have 3 digits.
|
Alright, simple and straight to the point explanation. My C Primer Plus book didn't explicity state this. Thanks! :)
|
Out of curiosity, how does the compiler differ between "\074", meaning octal character 74, and "\074", meaning a null byte followed by the characters '7' and '4'?
|
Quote:
Double quotes = string |
I got that. What I want to know is how you insert characters represented as octal numbers into a string.
|
Quote:
:
printf("This is the first letter of the alphabet: \101\n"); |
This is the first time i've ever seen ooble asking a question...
I got a question too, why is their an octal format and hex format when you can use the decimal format? |
Hex format gives you a view of the bit representations once you get the visualization down, because it's a power of 2 and decimal isn't. Octal is the same way, but is primarily a throwback to when busses weren't as wide. Hexadecimal requires that one invent 6 new numeric symbols (if you can call the traditional A-F an invention), whereas, with octal, you just toss a couple of the leftover ones, no imagination necessary.
|
Wow, a simple question has spurned an interesting conversation. Speaking of which is \377 the highest octal value you can represent since that is all eight bits set to 1?
|
| All times are GMT -5. The time now is 2:07 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC