Tabs \ t and spaces in C

Source: Internet
Author: User

(This article does not discuss tab and space indentation issues)

During programming, we often use multiple spaces or tabs to separate two strings. What are the differences between the two strings in the display effect?

Compare the output results of the following two lines of code:

Code 1:

Printf ();

Code 2:

Printf (););

Code 1 output:

Code 2 output result:

Obviously, the two 1 s on the right side of the output result of code 1 are aligned up and down, while the two 1 s on the right side of the output result of Code 2 are not aligned up and down, the reason why the output result of Code 2 is not correct is easy to understand, but why is the two 1 in the output result of code 1 aligned?

This involves skipping a few spaces on the tab \ t.

\ T whether to skip a few spaces is not specified, there is no standard, each output device will require their own device \ t will locate an integer unit multiple, for example, some devices require that \ t be positioned at an integer multiple of 8 characters. If a string contains n characters before the Tab character \ t, \ t will skip 8-n % 8 spaces.

 

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.