# Another strange output-printf

## Recommended Posts

I really couldn't understand why the output is a
#include<stdio.h>
int main()
{
printf("%c",'\141');
}


##### Share on other sites
Unless that's a typo, that should produce a compiler warning because "\1" isn't a valid escape code.

It works because the printf "%c" in printf tells it to expect a character as an argument, and 141 is the ASCII code for 'a'. I guess the compiler is converting '141' to 141, but I'm not sure why.

##### Share on other sites
Oh..I remembered the decimal values i.e 97 for a. So, basically this is in octal.

##### Share on other sites
In a string literal a backslash followed by one to three octal digits (0-7 inclusive) forms an octal escape sequence and specifies the value of a single character in octal notation. The value 141 in octal is 97 in decimal and corresponds to the ascii code for 'a'.

Σnigma

##### Share on other sites
Right, a character literal that begins with a backslash is an octal value.

##### Share on other sites
Thanks Again... but can't add to anyone's reputation. There are some a**holes here who rate people negative unneccesary.
I tried giving reputation to all but I guess I can't give.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627721
• Total Posts
2978804

• 10
• 9
• 21
• 14
• 12