Interesting things in C Language _ spaces in C Language

Source: Internet
Author: User

Today, I started to learn C language by myself. In fact, I have been familiar with some programming knowledge of C language for a long time, but I have always found that my language skills are not solid enough. Therefore, I want to study C language well.

First, perform a test:

Exp_1:

# Include <stdio. h>

Int main (INT argc, char * argv [])

{

Printf ("Hello word

");

Getch ();

}

I don't know what you thinkProgramThere are no exceptions. From the C language books I have learned, I have obtained the following knowledge point: During the C language compilation process, spaces are not compiled, that is to say, if we program in C LanguageCodeInsert one, two, three, or more spaces, and the compilation result is the same.

For example:

Exp2: Define function variables

Int iage; // a space

Int iage; // multiple Spaces

Obviously, the above two C statements defining integer data have the same effect.

Exp3: Assignment and operation statement

Iage = 100; // a space between the left and right values of the value assignment operator

Iage = 100; // there is no space between the left and right values of the value assignment operator.

Iage + = 100; // there is no space between addition operations

Iage + = 100; // space exists between addition operations

Obviously, these languages are also true.

Does it mean that spaces in the C language compiler can be ignored?

Although the examples above prove that in some cases, the C compiler ignores spaces, but it cannot mean that a space is the same as two spaces in all places.

If you compile on wintc or on Turbo C, you can find that the previous exp1 cannot be compiled:

Message: A string without ending quotation marks -- "printf (" Hello word

This proves that spaces can not be added randomly in the C language.

When can space be ignored?

The following is a simple summary of several items, thank you for bending over to find the bricks ..............................

1. No space is allowed between the characters that constitute the keywords specified in the C standard. For example:

Int cannot write I nt

2. When defining user-defined identifiers, there cannot be spaces between characters that constitute the identifiers. For example:

Int iage; cannot be written as int I age;

3. There cannot be spaces between operators composed of multiple characters defined in C language. For example:

Iage + = 100; there is no space between the + = in this place. This phenomenon is limited to two or three character operators. Of course? Except for this operator.

4. Edit CSource codeThe user-defined string literal value is usually between the quotation marks of a String constant and cannot contain spaces brought by carriage return. For example:

"Hello word ";

Cannot be written as "Hello word"

";

In the fourth case, the "\" symbol can be used to eliminate the side effects of carriage return during editing.

For example, "Hello word" can be defined

"Hello word \

"

* ** Focus on the Backslash "\"

We know that when we do not write the next C language statement in one line, we can use the "\" to continue the line, but we can still use it when we can write the code in one line. For example:

Exp4:

Printf ("Hello word \! ");

What will be output here? In general, we learned that the first string parameter in printf is output as is, that is, hello word \!

However, the actual output is not described above,:

Hello word!

That is to say, in the C language compiler, when we use a separate "\", it is a line feed, even if this line is the same. (Except when an escape sequence exists ).

 

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.