C中经典的helloworld程序

来源:互联网 发布:中华大字典软件 编辑:程序博客网 时间:2024/05/18 13:08

hello world 程序不同实现方法:

1. 利用宏定义

#include "stdio.h"
#define say(str) puts(#str)
int  main()
{
 return say(hello world!);   
}

2. 教科书式写法

#include<stdio.h>

int main()
{
printf("hello world\n");
puts("hello world\n");
}

3. 

#include <stdio.h> 
int main() 

return puts(&"Do not say: Hello world!"[12]); 

4. 退出是运行自定义的退出函数

#include <stdio.h> 
#include <stdlib.h> 
void say() 

printf("world!"); 

void sth() 

printf("Hello "); 

int main() 

return atexit(say), atexit(sth); 


hello world 程序在运行的生命周期经过:

预处理阶段:将头文件的内容插入程序,得到文本程序

编译阶段:编译阶段将上一步骤得到的文本程序通过编译器得到汇编语言程序

汇编阶段:将汇编语言翻译成机器语言指令,及hello.o目标程序,hello.o 是一个二进制文件

链接阶段:printf 有一个单独的文件pritnf.o 链接器将该文件链接到hello.o 程序中,生成可执行文件。


可见小小的helloword程序也大有学问啊!

0 0
原创粉丝点击