zoukankan      html  css  js  c++  java
  • C语言 Hello World

    目录

    零基础 Python 学习路线推荐 : C/C++ 学习目录 >> C 语言基础入门

    一.Hello World 源码

    hello world.cpp 内容如下:

    /************************************************************************/
    //@Author:猿说编程
    //@Blog(个人博客地址): www.codersrc.com
    //@File:C语言 Hello World
    //@Time:2021/05/21 08:00
    //@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
    /************************************************************************/
    
    // hello world.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <stdio.h>
    
    int main(void)
    {
        printf("HelloWorld!");
        return 0;
    }
    

    1.#include – 预处理器指令

    预处理器发现 #include 指令后就会去寻找 #include <> 或者 #include “”里的文件名

    /************************************************************************/
    //@Author:猿说编程
    //@Blog(个人博客地址): www.codersrc.com
    //@File:C语言 Hello World
    //@Time:2021/05/21 08:00
    //@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
    /************************************************************************/
    
    
    //写法一:推荐
    #include <stdio.h>
    //写法二:不推荐
    #include "stdio.h"
    

    #include <stdio.h> 会直接在系统目录搜索 stdio.h ,如果系统目录也搜索不到,直接报错:No such file or directory!

    include “stdio.h” 首先在工程目录搜索 stdio.h ,如果工程目录搜索不到,会继续在系统目录搜索 stdio.h ,如果系统目录也搜索不到,直接报错:No such file or directory!

    ** 对比可以发现:虽然第一种写法和第二种写法效果一样,但是第二种查找头文件的时候更耗时间,所以,系统的头文件推荐使用第一种写法!**

    2.main 函数 – 入口函数

    main 函数是 C 语言 程序的入口函数,必不可少,程序没有 main 函数就好比人不喝水,不吃饭!(强行记忆)

    3.printf 函数

    printf 是头文件 stdio.h 里面的一个函数,只有包含了 stdio.h 才能使用,当前 printf 是在控制台上格式输出一条信息,当前输出的内容是 HelloWorld! ,所以在控制台能看到一条 HelloWorld! 语句,该函数的使用会继续在后面的文章讲解。

    4.return 0

    return 意味着 mian 函数结束;main 函数是 C 语言的主函数,主函数结束,整个程序结束!Game Over!

    二.Visual Studio 运行生成项目

    代码有了,说了一天 Hello World 结果毛都没看到一个,如何使用 Visual Studio 编译代码生成 exe 可以执行文件呢?

    1.使用快捷键 Ctrl + F5

    2.点击 本地 Windows 调试器

    点击 绿色 的三角形按钮,结果发现一个黑窗口一闪而过,这个是表示代码执行结束了 return 0 了;

    你也可以找到工程文件夹下面有一个 debug 文件夹,里面有刚刚生成的 hello world.exe,直接使用 cmd 命令运行也能看到最终效果:

    三.猜你喜欢

    1. 安装 Visual Studio
    2. 安装 Visual Studio 插件 Visual Assist
    3. Visual Studio 2008 卸载
    4. Visual Studio 2003/2015 卸载
    5. 设置 Visual Studio 字体/背景/行号
    6. C 语言 Hello World

    未经允许不得转载:猿说编程 » C 语言 Hello World

    本文由博客 - 猿说编程 猿说编程 发布!

  • 相关阅读:
    Spring中@Autowired注解与自动装配
    Nginx教程(一)-全面认知
    hadoop-mapreduce 详解
    python with hadoop
    大数据架构与技术选型
    hadoop-集群搭建
    虚拟机Vmware-网络配置
    linux 忘记密码
    高效编程之 小技巧归纳
    kafka 教程(四)-原理进阶
  • 原文地址:https://www.cnblogs.com/shuopython/p/15088103.html
Copyright © 2011-2022 走看看