“Hello World”没有分号的差异 [英] "Hello World" without semicolon with a difference

查看:101
本文介绍了“Hello World”没有分号的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否可以编写打印Hello World的C程序。在屏幕上没有

在整个程序中只有一个分号?

这里的额外限制是你不允许使用if,while,switch等。 />

到目前为止,我认为这可以通过插入主要

中的printf语句来完成,如下所示:


int main(int argc = printf(" Hello world))

{

}

注意:ANSI C中不允许这样做,默认参数更像是一个C ++概念。


即使这不起作用。它编译和运行但不打印任何东西。


解决方案是这个问题可能在c(或c ++中)?

Hi,

Is it possible to write a C program that prints "Hello World" on screen without
having a single semi-colon in the entire program?
The extra constraint here is that u r not allowed to use if,while,switch etc.

So far,i figured this could be done by insertint the printf statement in main
as shown:

int main(int argc=printf("Hello world")
{
}
Note:This is not allowed in ANSI C,default arguments are more a C++ concept.

Even this doesnt work.It compiles & runs but doesnt print anything.

Is the solution to this question possible in c(or c++ for that matter)?

推荐答案



我相信除非你认为这是一个有效选项:

#include< stdio.h>


#define WEE put(Hello World!);


int main(int argc,char * argv []){

WEE

}

... in事实上要在屏幕上打印你需要一个指令..并且每个指令后面都需要一个分号。


祝你好运。


ankursinha写道:

I believe not unless you consider this a valid option:
#include <stdio.h>

#define WEE puts( "Hello World!" );

int main( int argc, char * argv[] ) {
WEE
}
...in fact to print on the screen you need an instruction.. and
in C every instruction has to be followed by a semi-colon.

Best regards.

ankursinha wrote:


是否可以编写一个打印Hello World的C程序。屏幕上没有
在整个程序中有一个分号?
这里的额外限制是你不允许使用if,while,switch等

到目前为止,我认为这可以通过插入主要的


int main(int argc = printf(" Hello world))
{
即使这不起作用。它编译和运行但不打印任何东西。这个问题的解决方案是否可以用c(或c ++)?
Hi,

Is it possible to write a C program that prints "Hello World" on screen without
having a single semi-colon in the entire program?
The extra constraint here is that u r not allowed to use if,while,switch etc.

So far,i figured this could be done by insertint the printf statement in main
as shown:

int main(int argc=printf("Hello world")
{
}
Note:This is not allowed in ANSI C,default arguments are more a C++ concept.

Even this doesnt work.It compiles & runs but doesnt print anything.

Is the solution to this question possible in c(or c++ for that matter)?



-

Roberto Nunnari -software engineer -

mailto:ro ** @nunnisoft.ch
http: //www.nunnisoft.ch

Residenza Boschetto 12电话/传真:+ 41-91-6046511

6935 Bosco Luganese"mobile :+ 41-76-3208561

瑞士(oo)
======================== oOO ==(_)== OOo ============ = ===========


--
Roberto Nunnari -software engineer-
mailto:ro**@nunnisoft.ch
http://www.nunnisoft.ch
Residenza Boschetto 12 tel/fax: +41-91-6046511
6935 Bosco Luganese """ mobile: +41-76-3208561
Switzerland (o o)
========================oOO==(_)==OOo============= ===========


ankursinha写道:
ankursinha wrote:



是否可以编写一个打印Hello World的C程序。屏幕上没有
整个程序中有一个分号?


回答#1:不,因为C语言没有概念

a" screen。


答案#2:是,如下


?? = include< stdio.h>

int main(void){

put(Hello,world!);;

返回10 ??''012 ;;

??>


观察没有单个分号。

这里的额外约束是你不允许使用if,while,switch等等。


在这种情况下,问题是不可能的。 (假设:等等

包括左括号字符''(''。)

到目前为止,我认为这可以通过insertint printf语句来完成主要如图所示:

int main(int argc = printf(" Hello world))


注意:这是不允许的在ANSI C中,默认参数更像是一个C ++概念。

即使这不起作用。它编译和运行但不打印任何东西。

这个问题的解决方案是否可行在c(或c ++中)?

Hi,

Is it possible to write a C program that prints "Hello World" on screen without
having a single semi-colon in the entire program?
Answer #1: No, because the C language has no concept of
a "screen."

Answer #2: Yes, as follows

??=include <stdio.h>
int main(void) {
puts ("Hello, world!");;
return 10??''012;;
??>

Observe that there are no single semi-colons.
The extra constraint here is that u r not allowed to use if,while,switch etc.
In that case, the problem is impossible. (Assumption: "etc"
includes the open parenthesis character ''(''.)
So far,i figured this could be done by insertint the printf statement in main
as shown:

int main(int argc=printf("Hello world")
{
}
Note:This is not allowed in ANSI C,default arguments are more a C++ concept.

Even this doesnt work.It compiles & runs but doesnt print anything.

Is the solution to this question possible in c(or c++ for that matter)?




DYOH。或者如果你不是DYOH,至少是RTFW。


-
Er*********@sun.com


ankursinha写道:
ankursinha wrote:
是否可以编写一个C程序,在屏幕上打印Hello World而不用
在整个程序中单个分号?
这里的额外约束是你不允许使用if,whil e,切换等。
Is it possible to write a C program that prints "Hello World" on screen without
having a single semi-colon in the entire program?
The extra constraint here is that u r not allowed to use if,while,switch etc.




这会调用未定义的行为,因为可变长度数组类型

与普通数组类型不兼容,但是这是我最接近的
。显然是C99。


#include< stdio.h>

int main(int argc,char * argv [static printf(" ; Hello World \ nn),0])

{

}


还有


#error" Hello World"


但我不认为这是一个程序。


杰里米。



This invokes undefined behaviour, because variable length array types
aren''t compatible with normal array types, but it''s the closest I
could get. It''s C99, obviously.

#include <stdio.h>
int main(int argc, char *argv[static printf("Hello World\n"), 0])
{
}

There''s also

#error "Hello World"

but I don''t consider that a program.

Jeremy.


这篇关于“Hello World”没有分号的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆