What do you mean by '\o<octal number>'?

  • Thread starter Thread starter dE_logics
  • Start date Start date
  • Tags Tags
    Mean
Click For Summary

Discussion Overview

The discussion revolves around the interpretation and usage of octal escape sequences in programming, specifically the notation '\o' and its alternatives. Participants explore how different representations of octal and hexadecimal values are processed in functions like printf.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant questions the meaning of '\o' and notes that attempts to use it result in a compiler error, while using '\' works correctly.
  • Another participant clarifies that '\ooo' can be used with one to three octal digits, providing examples but specifying that 'o12' is not valid.
  • It is mentioned that '\xhh' can be used for hexadecimal digits, with examples given for both octal and hexadecimal representations.
  • A participant corrects a previous claim, stating that octal \042 corresponds to ASCII code 34, which is the double-quote character, not 52.
  • There is a confirmation regarding the dropping of the leading zero in octal representations.

Areas of Agreement / Disagreement

Participants express differing views on the validity of certain escape sequences and their corresponding ASCII values, indicating that multiple interpretations and corrections are present without a clear consensus.

Contextual Notes

Some assumptions about the programming environment and specific language behavior are not fully explored, and there are unresolved details regarding the handling of escape sequences across different compilers.

dE_logics
Messages
742
Reaction score
0
book said:
In addition, an arbitrary byte-sized bit pattern can be specified by

'\ooo'

where ooo is one to three octal digits (0...7) or by "
I'm not sure what they mean here...can someone explain?

When ever I do, for e.g -

"\o7" or "\o42" in printf to try and print ASCII code 7 or 52 (decimal)

Compiler returns \o is not recognized.

However if I do "\07" or "\042" I get the characters 7 and 52 (as in ASCII code).


My question is, what is this 'o'?
 
Technology news on Phys.org
You can use "\ooo" where "ooo" is 1 to 3 octal digits. In other words, "ooo" can be "1", "304", "12", "77"...but not "o12."

You can also use "\xhh", where "hh" is 1 or 2 hexadecimal digits...ie, "\x34" or "\x9f" or "\xb."

This is the complete ascii table:
http://www.cs.utk.edu/~pham/ascii_table.jpg

Some of the characters have special escape codes defined, such as "\n" for newline, which has hex value "A" and octal value "012", therefore the following are all equivalent:

\n
\xa
\xA (pretty sure this is case insensitive)
\012
\12 (im pretty sure the leading zero can be dropped)
 
Last edited by a moderator:
dE_logics said:
However if I do "\07" or "\042" I get the characters 7 and 52 (as in ASCII code).
Octal \042 is the code for the character with ASCII code 34, not 52. This character is the double-quote, ".
 
junglebeast said:
(im pretty sure the leading zero can be dropped)

Yes it can.

Thanks everyone!
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
16K
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
39
Views
6K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
1
Views
2K