Jump to content
  • Advertisement
Sign in to follow this  
TEUTON

Another strange output-printf

This topic is 4462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!