Differences between space characters, empty characters, character array Terminator, line feed, and carriage return in C Language

Source: Internet
Author: User
Tags control characters
  Space Character And NULL Character It is different. In ASCII, the ASCII code of the Space symbol is 32, while the empty character is 0, and the two are completely different 2 characters.

NULL Character It is generally used to describe the end of a string. It is actually a type of control character, but it cannot be understood as having no character. It should be understood as representing nothing. for example, the carriage return 0x0a and line feed 0x0d are not displayed, but they are also a type of control characters. (These characters were previously used for printers, so many of them are useless)

 

String Concept: In C, a string is a series of valid characters (including letters, numbers, escape characters, and so on,Use '\ 0' as the string end flag. '\ 0' is a "null operation" character. It does not perform any operation, but is a flag. '\ 0'CodeThe value is 0, which is not counted in the length of the string.


Note:

When receiving stringsIf scanf receives the string, it cannot contain spaces. Otherwise, it will use spaces as the end character of the string.. If you type Harry Potter, scanf can only get the word Harry. ThereforeIf you receive spaces, you can use the gets () function..

Is the output space character in C language different from that in output space?

 
The output space is displayed as a space on the screen. However, empty characters are not displayed. Because the null character is used as the end sign of a string.

 

Line feed (\ n, ASCII code: 10)That is, the cursor moves down a line but does not move to the beginning of this line,Press enter (\ r,ASCII code: 13) Is to return to the beginning of the current row without moving down a row.

EnterAfter pressing it, \ n \ r will be executed, which is the general meaning of the carriage return. Therefore, you can view the text in a hexadecimal file, \ n \ r will be found at the end of the row ".

Tab(\ T, ASCII code: 9)It is a Tab character. It is used to reserve the display width of 8 characters for alignment.

 

Related Article

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.