6个变态的C语言Hello World程序

下面的六个程序片段主要完成这些事情:

  1. 输出Hello, World

  2. 混乱C语言的源代码

下面的所有程序都可以在GCC下编译通过,只有最后一个需要动用C++的编译器g++才能编程通过。

hello1.c

 #define _________ }
    #define ________ putchar
    #define _______ main
    #define _(a) ________(a);
    #define ______ _______(){
    #define __ ______ _(0x48)_(0x65)_(0x6C)_(0x6C)
    #define ___ _(0x6F)_(0x2C)_(0x20)_(0x77)_(0x6F)
    #define ____ _(0x72)_(0x6C)_(0x64)_(0x21)
    #define _____ __ ___ ____ _________
    #include<stdio.h>
    _____

hello2.c 

#include<stdio.h>
    main(){
      int x=0,y[14],*z=&y;*(z++)=0x48;*(z++)=y[x++]+0x1D;
      *(z++)=y[x++]+0x07;*(z++)=y[x++]+0x00;*(z++)=y[x++]+0x03;
      *(z++)=y[x++]-0x43;*(z++)=y[x++]-0x0C;*(z++)=y[x++]+0x57;
      *(z++)=y[x++]-0x08;*(z++)=y[x++]+0x03;*(z++)=y[x++]-0x06;
      *(z++)=y[x++]-0x08;*(z++)=y[x++]-0x43;*(z++)=y[x]-0x21;
      x=*(--z);while(y[x]!=NULL)putchar(y[x++]);
    }

hello3.c

 #include<stdio.h>
    #define __(a) goto a;
    #define ___(a) putchar(a);
    #define _(a,b) ___(a) __(b);
    main()
    { _:__(t)a:_('r',g)b:_('$',p)
      c:_('l',f)d:_(' ',s)e:_('a',s)
      f:_('o',q)g:_('l',h)h:_('d',n)
      i:_('e',w)j:_('e',x)k:_('\n',z)
      l:_('H',l)m:_('X',i)n:_('!',k)
      o:_('z',q)p:_('q',b)q:_(',',d)
      r:_('i',l)s:_('w',v)t:_('H',j)
      u:_('a',a)v:_('o',a)w:_(')',k)
      x:_('l',c)y:_('\t',g)z:___(0x0)}

hello4.c

 int n[]={0x48,
    0x65,0x6C,0x6C,
    0x6F,0x2C,0x20,
    0x77,0x6F,0x72,
    0x6C,0x64,0x21,
    0x0A,0x00},*m=n;
    main(n){putchar
    (*m)!=''?main
    (m++):exit(n++);}

hello5.c

 main(){int i,n[]={(((1<<1)<<(1<<1)<<(1<<
    1)<<(1<<(1>>1)))+((1<<1)<<(1<<1))), (((1
    <<1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<<(
    1<<1)<<(1<<1))+((1<<1)<<(1<<(1>>1)))+ (1
    <<(1>>1))),(((1<<1)<<(1<<1)<<(1<<1)<< (1
    <<1))-((1<<1)<<(1<<1)<<(1<<(1>>1)))- ((1
    <<1)<<(1<<(1>>1)))),(((1<<1)<<(1<<1)<<(1
    <<1)<<(1<<1))-((1<<1)<<(1<<1)<<(1<<(1>>1
    )))-((1<<1)<<(1<<(1>>1)))),(((1<<1)<< (1
    <<1)<<(1<<1)<<(1<<1))-((1<<1)<<(1<<1)<<(
    1<<(1>>1)))-(1<<(1>>1))),(((1<<1)<<(1<<1
    )<<(1<<1))+((1<<1)<<(1<<1)<<(1<<(1>>1)))
    -((1<<1)<<(1<<(1>>1)))),((1<<1)<< (1<<1)
    <<(1<<1)),(((1<<1)<<(1<<1)<<(1<<1)<<(1<<
    1))-((1<<1)<<(1<<1))-(1<<(1>>1))),(((1<<
    1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<< (1
    <<1)<<(1<<(1>>1)))-(1<<(1>>1))), (((1<<1
    )<<(1<<1)<<(1<<1)<<(1<<1))- ((1<<1)<< (1
    <<1)<<(1<<(1>>1)))+(1<<1)), (((1<<1)<< (
    1<<1)<<(1<<1)<< (1<<1))-((1<<1)<< (1<<1)
    <<(1<<(1>>1)))-((1<<1) <<(1<< (1>>1)))),
    (((1<<1)<< (1<<1)<<(1<<1)<< (1<<1))- ((1
    <<1)<<(1<<1)<<(1<<1))+((1<<1)<< (1<<(1>>
    1)))), (((1<<1)<<(1<<1) <<(1<<1))+(1<<(1
    >>1))),(((1<<1)<<(1<<1))+((1<<1)<< (1<<(
    1>>1))) + (1<< (1>>1)))}; for(i=(1>>1);i
    <(((1<<1) <<(1<<1))+((1 <<1)<< (1<<(1>>1
    ))) + (1<<1)); i++) printf("%c",n[i]); }

hello6.cpp

下面的程序只能由C++的编译器编译(比如:g++)

 #include <stdio.h>
    #define _(_) putchar(_);
    int main(void){int i = 0;_(
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++i)_(++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++i)_(++++++++++++++
    i)_(--++i)_(++++++i)_(------
    ----------------------------
    ----------------------------
    ----------------------------
    ----------------------------
    ----------------i)_(--------
    ----------------i)_(++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++++
    ++++++++++++++++++++++++++i)
    _(----------------i)_(++++++
    i)_(------------i)_(--------
    --------i)_(----------------
    ----------------------------
    ----------------------------
    ----------------------------
    ----------------------------
    ------i)_(------------------
    ----------------------------
    i)return i;}

转自:http://coolshell.cn/articles/914.html

原创文章,作者:s19930811,如若转载,请注明出处:http://www.178linux.com/2259

(0)
s19930811s19930811
上一篇 2016-05-07
下一篇 2016-05-09

相关推荐

  • heartbeat实现高可用集群(2)

    [[ heartbeat v2 + crm ]] 环境 node1 192.168.1.35 node2 192.168.1.36 fip 192.168.1.81 daemon httpd ha web service ip httpd node1&2 # vim ha.cf crm on # cd # rpm -ivh heartbeat-gui…

    Linux干货 2017-11-03
  • Linux命令帮助及history命令的使用

    1.Linux命令帮助的获取详解 在Linux中获取命令帮助时,内部命令和外部命令的获取方式是有区别的: 即  (1)内部命令:#help COMMAND ?            #man bash  (2)外部命令:<1> # COMMAND –hel…

    Linux干货 2016-08-05
  • httpd 安装配置

    web 服务介绍 web服务时一种应用程序的服务,它所提供的最主要的信息是一种超文本标记语言(HTML)、多媒体资源(如:视频、图片、音乐等)。HTML是一种纯文字的文本信息,通过所谓的标签来规范所要显示的内容格式,在客户端通过浏览器的形式对HTML及多媒体资源进行解析,然后呈现在终端上。主要由http和https协议实现 http协议 HTTP是一个属于应…

    Linux干货 2016-11-01
  • 第十周

    请详细描述CentOS的启动流程     启动第一步–加载BIOS         当打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它,这是因为BIOS中包含了CPU的相关信息、设备启动顺序信息、硬盘信…

    Linux干货 2017-01-03
  • Http协议中的各种长度限制总结

    HTTP1.0的格式 request(HTTP请求消息)结构:一个请求行.部分消息头,以及实体内容,其中的一些消息内容都是可选择的.消息头和实体内容之间要用空行分开. GET /index.html HTTP/1.1 //请求头,下面都是消息头.Accept: */*Accept-Languang:en-usConnection:keep-aliveHost…

    Linux干货 2015-04-04
  • RAID[Redundant Array of Independent Disks | 独立硬盘冗余阵列 ]

    前言 一个技术要知其然还要知其所以然 RAID 独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列 RAID的基本思想 其基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到…

    Linux干货 2016-05-20