Printing an octal number with the printf command

I am trying to understand the functionality of printf for octal numbers. if I write code like:

int main()
{
  char *s = "\123";
  printf("%s",s);
}

This gives me a result like S, which is actually correct, since ASCII S is 123 in octal. But my question is how the compiler identifies a sequence of numbers to convert from octal. eg:

char *s = "\123456" 

will give the result as S456

This is that octal conversion requires a maximum of 3.

Is there a maximum limit within which an octal must be specified (an octal number with eight digits will be 777)

, 255 ascii ( 377), , 777, asc ascii, , , , ascii, . , /os

, , : -)

+5
3
  • . - . 6.4.4.4 :

    - :
    \
    \
    \

    - :
         \x
        

  • escape- \777, . escape- , .

  • 128 ASCII (0-127). , \000 \177 ASCII. , \377 8- char \777 ( , escape-) wchar_t. :

    escape- unsigned char , wchar_t .

    unsigned char - 8- , escape- \377 , - \xff. 32- wchar_t \xffffffff.

+9

C99 (, ) octal-escape-sequence :

octal-escape-sequence:
    \ octal-digit
    \ octal-digit octal-digit
    \ octal-digit octal-digit octal-digit

, octal-escape-sequence 3- ( 0 7).

, :

, escape-, . .

,

escape- - , escape-.

:

escape- unsigned char , wchar_t .

, \777 , 8 (CHAR_BIT < 9). - , , undefined, .

+4

'0', . : 0123

'0x', hexidecimal . : 0x123

. : 123

char * s = "\ 123456"

escape-\123 - . , 3 , 0 255, 3 .

By the way, the decimal digit 123 is "S", so your string is "S456".

0
source

All Articles