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

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

The discussion clarifies the use of octal escape sequences in programming, specifically the syntax '\ooo' where 'ooo' represents one to three octal digits. Users reported that using '\o7' or '\o42' results in an error, while '\07' and '\042' correctly print the ASCII characters for decimal values 7 and 34, respectively. The conversation also highlights the equivalence of various escape sequences, such as '\n', '\xA', and '\012', emphasizing the importance of understanding octal and hexadecimal representations in ASCII coding.

PREREQUISITES
  • Understanding of ASCII character encoding
  • Familiarity with escape sequences in programming languages
  • Knowledge of octal and hexadecimal number systems
  • Experience with printf function in C or similar languages
NEXT STEPS
  • Research the use of escape sequences in C programming
  • Learn about ASCII values and their corresponding octal and hexadecimal representations
  • Explore the differences between octal and hexadecimal escape sequences
  • Study the printf function and its formatting options in C
USEFUL FOR

Programmers, software developers, and students learning about character encoding and escape sequences in languages like C.

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
2K
Replies
39
Views
6K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
1
Views
2K