开发者

c syntax in two different lines?

I have this simple question about c syntax. When we write :

  printf("hello world
  ");

compiler produces an error. Why? In this other case:

  for (i = 0; i < MAXLINE - 1      
  && (c=getchar)) != EOF && c != '\n'; ++i)

everything compiles fine. What is the general rule fo开发者_如何学Gor all this?

Thank you !


A string literal ("...") cannot contain a bare newline.

If you want a newline character in the string, use the \n escape sequence (`"hello world\n")


Because you're breaking a string literal, which isn't allowed, in the first example. In the second, you're just wrapping the syntax over multiple lines. For example:

printf("hello world"
);

will compile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜