English 中文(简体)
这部法典的输出是什么?
原标题:What s the output of this code and why?

有了以下法典,这部法典的产出是什么?

#include <stdio.h>

int main() {
        printf("Hello world
"); // \
        printf("What s the meaning of this?");
        return 0;
}
最佳回答

The backslash at the end of the 4th line is escaping the following new line so that they become one continuous line. And because we can see the // beginning a comment, the 5th line is commented out.

也就是说,你的法典相当于:

#include <stdio.h>

int main() {
        printf("Hello world
"); // printf("What s the meaning of this?");
        return 0;
}

产出只是一个新行的“Hello世界”。

<><>Edit>: 正如Erik和Pmg两人都说过的那样,在C99而不是C89就是如此。 信贷到期的信贷。

在翻译的第二阶段(ISO/IEC 9899:1999 §5.1.1.2):

Each instance of a backslash character () immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.

问题回答

It s "Hello world ". Didn t you try? Line continuation (and e.g trigraphs) are well documented, look it up. A syntax highlighting editor (e.g. Visual Studio with VA X) will make this obvious.

注:这一工程在C99和C++-not进行。 C89

拖拉的后.导致下线延伸到下线,以压倒下,即使它含有一部分评论。 这几乎永远是无意的(除非它带有蓄意的混淆,否则就会造成ug,除非下行完全是白人空间或评论本身。

This happens because line-splicing occurs in translation phase 2, while removing comments happens in phase 3.

新的汇编者将警告单线评论将持续到下行(我并不确切地说,可能需要多少警告):

  • GCC 4.5.1 (MinGW)

    C:	emp	est.c:4:34: warning: multi-line comment
    
  • MSVC 9 (VS 2008) or 10 (VS 2010):

    C:	emp	est.c(5) : warning C4010: single-line comment contains line-continuation character
    

C: emp est.c:4:34: 警告:多线评论

C: emp est.c(5) : warning C4010: single-line comment contains line-continuation character





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签