最简单的程序(Hello world!及详解)

目录

  1. Hello world!程序
  2. 预处理命令
  3. 头文件
  4. 主函数
  5. 函数返回值
  6. 注释
  7. Hello world!加强版
一、最简单的C程序 Hello world!
#include<stdio.h>        //编译预处理命令
int main()               //定义主函数,主函数类型为整型(int)
{                        //函数开始的标志
    printf("Hello world!");   //输出内容
    return 0;            //函数执行完毕时返回一个整数值 0
}                        //函数结束的标志

运行结果:
在这里插入图片描述

二、预处理指令(#include<stdio.h>

1.作用把 stdio.h 头文件的内容读进来
2.其它预处理命令:#define

三、头文件(stdio.h

stdio.h 文件中具有输入(scanf),输出(printf)等函数的原型声明

  1. std表示标准:standard
  2. i 表示输入: input
  3. o 表示输出:output
  4. .h 表示头文件 head (文件后缀名)
四、主函数(main)

每一个C语言程序都必须有一个main,且主函数有且仅有1个。

五、函数的返回值(return 0)

主函数main的返回值为 0 时表示程序正常退出
返回值为非零时,表示程序异常退出

六、注释

C语言允许两种注释

第一种:以 // 开始的单行注释
第二种:以 /* 开始,以 */ 结束的多行注释(块式注释)

七、Hello world!加强版

加强版 1………………

#include<stdio.h>
int main()
{
    printf("\tHello world!\n");   // \n 换行符 \t 横向空格
    return 0;
}

执行结果:
在这里插入图片描述
加强版 2………………

#include<stdio.h>
int main()
{
    printf("\n\tHello\n\nworld!\n");   // \n 换行符 \t 横向空格
    return 0;
}

执行结果:
在这里插入图片描述
加强版3……………欢迎来到C语言的世界

扫描二维码关注公众号,回复: 11107610 查看本文章
#include<stdio.h>
int main()
{
    printf("\n\t***********************\n");
    printf("\t*                     *\n");
    printf("\t* 欢迎来到C语言的世界 *\n");
    printf("\t*                     *\n");
    printf("\t***********************\n"); 
    return 0;
}

执行结果:
在这里插入图片描述
通过 \n 换行符,\t 横向空格等等一些转义字符的结合和设计,可以让你写的程序,输出内容更加美观和有吸引力。
…………………………
以上是我经过一段时间对C语言的学习,总结出来的最简单的C程序中各种内容的功能以及加强版Hello world!
如果以上内容有什么错误的地方,请大家指正(共同进步)

这是我第写的第一个C程序,不知道你是不是!!!

那时候,在写这个程序的时候,在电脑上慢慢腾腾,反复修改,最后当在屏幕上输出 Hello world! 时心里猛然感叹道:从此算是走上了程序猿这条 “不归路” ……

在这里插入图片描述

发布了25 篇原创文章 · 获赞 54 · 访问量 898

猜你喜欢

转载自blog.csdn.net/weixin_46022083/article/details/105199355