vico
vico

Reputation: 18171

Using octal escape sequence in C

Why

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

prints 1 in output. I expect something like =

Upvotes: 1

Views: 1583

Answers (3)

The Mighty Programmer
The Mighty Programmer

Reputation: 1252

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/

Upvotes: 2

haccks
haccks

Reputation: 106052

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");

Upvotes: 1

Cubbi
Cubbi

Reputation: 47448

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

Why do you expect '='?

Upvotes: 5

Related Questions