The backslash in C/C ++ !!!

Source: Internet
Author: User

Today I met a pen question from a company (despised ):

Char s [] = "\ 141 \ 141abc \ t"; cout <S <Endl; cout <strlen (s) <Endl; // What is the output result?

Answer:

\ 141 AABC

9

(If you are a big bull, you will know the answer and the following things will not look at it, just put your younger brother in the dark and don't despise me)

The first two characters are familiar to everyone. It must be a single character. The last 141 character is three characters. But when it comes to the \ 141 character, I am confused. How many characters are there? Actually

\ 141 is a character a. Why? Because \ 141 is a character representation with Octal numbers, \ O \ oo \ OOO three forms, of course, O must be the correct octal number (0 ~ 7 ).

So if we change s like this:

S [] = "\\ 141 \ 411abc \ t ";

The result is \ 141! 1abc, because \ 41 is! Character

Another problem is that the strlen () function is not counted as \ 0 ..

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.