简体   繁体   中英

Using octal escape sequence in C

Why

printf("%s\n","\061");

prints 1 in output. I expect something like =

061 octal == 49 decimal == 0x31 hex. That's the ASCII code for the character '1'

Why do you expect '=' ?

061 is an octal value having decimal value of 49 . 075 in octal is ASCII value for = .
Try this to print =

printf("%s\n","\075");

Edited as per @rici's advice (read comment below..)

Because \\ddd is character octal representation. \\061 is octal (not decimal) ascii code of '1' and whether you write '\\61' (it's not decimal) or '\\061' is one and same thing.

You should refer to ascii table for clarification .. http://www.asciitable.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM