1 C语言 gcc 介绍 C 语言编译 main接受参数

发布时间:2020-07-19 20:18:28

来源:51CTO

阅读:1216

作者:990487026

1第一个c语言的hello world

1.1include头文件包含

头文件包含,写法#include,

1.2main函数

这个就是C语言程序的入口,所有的C程序都是从main开始执行,一个C的源程序必须有一个main函数,也只能有一个main函数

1.3注释

//注释一行

/* */代表块注释,可以注释多行代码

1.4{}括号和代码块

代表一个代码单元

1.5声明

C语言规定,所有的变量和函数必须先声明,然后才能使用.

1.6C语言自定义名字的要求

可以使用大小写字母,下划线,数字,但第一个字母必须是字母或者下划线

字母区分大小写

变量名最好用英文,而且要有所含义,通过变量的名称就能猜测变量的意思。

1.7return语句

在C语言当中任何函数遇到return代表这个函数停止,当main函数遇到return,代表整个程序退出

return代表函数的返回值,如果返回类型是void,可以直接写return,而不需要返回任何值

2C语言的编译

2.1编译过程

2.2gcc编译选项

-o代表指定输出文件名

-E代表预编译

预编译处理include的本质就是简单的将include中的文件替换到c文件中

如果include包含的头文件在系统目录下,那么就用#include <>,如果包含的文件在当前目录下,那么用#inlclude“”

-S代表汇编

-c代表编译

Linux C学习

1,编写一个helloworld程序vim  hello.c

#include "stdio.h"

int main(){

printf("Hello World!\n\n");

return 0;

}

一步到位编译执行chunli@pc0003:/tmp/C$ gcc helloworld.C

chunli@pc0003:/tmp/C$ ./a.out

Hello World!

C编译过程chunli@pc0003:/tmp/C$ gcc --help

Usage: gcc [options] file...

Options:

-pass-exit-codes         Exit withhighest error code from a phase

--help                   Display this information

--target-help            Display target specific commandline options

--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]

Display specific types of command line options

(Use '-v --help' todisplay command line options of sub-processes)

--version                Display compiler version information

-dumpspecs               Display all of the built in specstrings

-dumpversion             Display the version of thecompiler

-dumpmachine             Display the compiler's targetprocessor

-print-search-dirs       Display the directories in thecompiler's search path

-print-libgcc-file-name  Displaythe name of the compiler's companion library

-print-file-name=  Display the full path to library

-print-prog-name= Display the full path to compiler component

-print-multiarch         Displaythe target's normalized GNU triplet, used as

a component in the library path

-print-multi-directory   Displaythe root directory for versions of libgcc

-print-multi-lib         Display the mapping between commandline options and

multiple library search directories

-print-multi-os-directory Display the relative path to OS libraries

-print-sysroot           Display the target librariesdirectory

-print-sysroot-headers-suffix Display the sysroot suffix used to findheaders

-Wa,           Pass comma-separated  on to the assembler

-Wp,           Pass comma-separated  on to the preprocessor

-Wl,           Pass comma-separated  on to the linker

-Xassembler        Pass  on tothe assembler

-Xpreprocessor     Pass  on tothe preprocessor

-Xlinker           Pass  onto the linker

-save-temps              Do not delete intermediate files

-save-temps=        Donot delete intermediate files

-no-canonical-prefixes   Do notcanonicalize paths when building relative

prefixes to other gcc components

-pipe                    Use pipes rather thanintermediate files

-time                    Time the execution of eachsubprocess

-specs=           Override built-in specs with the contents of

-std=         Assume that the input sources are for

--sysroot=    Use as the root directory for headers

and libraries

-B           Add to the compiler's search paths

-v                       Display the programsinvoked by the compiler

-###                     Like -v but options quotedand commands not executed

-E                       Preprocess only; do notcompile, assemble or link

-S                       Compile only; do notassemble or link

-c                       Compile and assemble,but do not link

-o                 Place the output into

-pie                     Create a positionindependent executable

-shared                  Create a shared library

-x             Specify the language of thefollowing input files

Permissible languages include: c c++ assembler none

'none' means revert to the default behavior of

guessing the language based on the file's extension

Options starting with -g, -f, -m, -O, -W, or --param areautomatically

passed on to thevarious sub-processes invoked by gcc.  Inorder to pass

other options on tothese processes the -W options must be used.

For bug reporting instructions, please see:

.

源C代码程序hello.c

第一步:预编译,把include文件的内容原封不动的放到源代码中gcc -o hello.i  hello.c

第二步:汇编,把预编译的结果变成汇编代码

第三步:编译,把汇编的结果变成二进制文件

第四步:链接,把编译的二进制文件与系统库连接起来chunli@pc0003:/tmp/C$ gcc -o hello.i -E hello.c

chunli@pc0003:/tmp/C$ gcc -o hello.s -S hello.c

chunli@pc0003:/tmp/C$ gcc -o hello.o -c hello.s

chunli@pc0003:/tmp/C$ gcc -o hello      hello.o

chunli@pc0003:/tmp/C$ ./hello

Hello World!

查看链接的库chunli@pc0003:/tmp/C$ ldd hello

linux-vdso.so.1=>  (0x00007fff217f8000)

libc.so.6 =>/lib/x86_64-linux-gnu/libc.so.6 (0x00007f5340914000)

/lib64/ld-linux-x86-64.so.2(0x00005654d9706000)

调用系统的程序vim hello.c

#include "stdio.h"

#include "stdlib.h"

int main(){

system("cat hello.c");

printf("Hello World!\n\n");

return 0;

}

编译gcc hello.c

执行./a.out

输出:#include "stdio.h"

#include "stdlib.h"

int main(){

system("cat hello.c");

printf("Hello World!\n\n");

return 0;

}

Hello World!

2.3printf执行原理

向屏幕输出的其他方式:chunli@pc0003:/tmp/C$ cat my_printf.c

#include

#include

#include

int main()

{

int i = 99;

printf("i=%d \n",i/0x10);

fwrite("abc\n",1,2,stdout);

//write("abc\n",4,STDOUT_FILENO,"abc");

return ;

}

C语言版计算器#include

#include

int main(int argc,char *args[])

{

if(argc <3 )

printf("请输入两个整数!\n");

else

{

int a = atoi(args[1]);

int b = atoi(args[2]);

int c = a+b;

printf("两个数的和是 %d \n",c);

}

return 0;

}

使用方法chunli@pc0003:/tmp/C$ !gcc

gcc calc.c

chunli@pc0003:/tmp/C$ ./a.out  3 3

两个数的和是 6

chunli@pc0003:/t

系统开发c语言技术参数,1 C语言 gcc 介绍 C 语言编译 main接受参数相关推荐

  1. 博奥智源科技,发布阅卷系统开发性能及技术功能分享

    在原有教育平台之阅卷系统一期的基础上,进行二次开发,满足市.校各级各类考试需求:考试流程与质量分析一体化设计,无需模块或系统间导入导出:要求平台既支持先扫后阅(客观题边扫描边识别边评分.主观题打破流水 ...

  2. AS400银行核心系统开发中的技术总结--数据字典和枚举值

    *数据字典和枚举值 在核心系统应用开发中,数据字典有举足轻重的作用.数据字典是对系统中所有字段的归纳抽象,需要规范同类字段的类型长度,方便定义和修改.     但是,在过去的核心系统中,数据字典的理解 ...

  3. Android系统开发篇(三) —— Android AOSP 9.0源码的同步与编译

    上回书我们说到,Ubuntu系统的安装和配置,既然是Android系统的开发,那我们就要有Android系统,那好,目标很明确,接下来我们就来操作,看看源码是怎么来的 一.Android 源码下载(同 ...

  4. a标签带参数跳转页面,并在跳转页面接受参数

    获取网页中url属性使用的是window.location对象 windows.location对象的属性 属性 描述 herf 返回的是当前页面的整个url protocol 返回的是url的协议 ...

  5. c语言vc数据类型长度,vc和gcc对C语言数据类型长度的定义

    vc2010中...... 测试代码: #include #include int main() { printf("in windows ...\n"); int l_char= ...

  6. 嵌入式系统开发技术(00)

    嵌入式系统开发技术(00) 目标 嵌入式系统基础 嵌入式处理器 嵌入式系统硬件组成 嵌入式系统软件 嵌入式系统的开发 目标 嵌入式系统基础 嵌入式系统的特点.分类.发展和应用 嵌入式系统的组成和微电子 ...

  7. 嵌入式系统开发笔记0_0:目录

    本系列文章将向大家介绍嵌入式系统开发的各方面知识. 本系列文章所介绍的知识和内容,除电路图设计外,其它均采用开源系统,所以你不会在这个系列文章中看到Keil.IAR等软件. 本系列文章涉及C.C++. ...

  8. 腾讯AI Lab:AI辅助诊疗系统面临的三大技术挑战

    感谢阅读腾讯AI Lab微信号第25篇文章.腾讯AI Lab总监杨巍4月12日在重庆召开的「2018中国互联网+数字经济峰会」上发表了主题为「人工智能辅助诊疗系统面临的三大技术挑战」的演讲,介绍了AI ...

  9. 嵌入式系统开发 (复习笔记)

    此书作者:李宥谋 主要是通过设计的ARM指令集和cpu内部的寄存器在内部的定时器的控制下工作.来完成数据运算处理和中断异常处理,外部数据通信通过连接外设接口处理. 目录 一.系统概述 (1)系统的概述 ...

最新文章

  1. MVC3+EF4.1学习系列(一)-------创建EF4.1 code first的第一个实例(强转)
  2. 源码时代php中级项目,PHP学科项目评比圆满结束
  3. 2.Java之路(Java语言开发环境搭建)
  4. webpack配置说明
  5. wordpress迁移后,伪静态404解决方法
  6. ADO.NET知识点
  7. linux编译时开启宏,【spec】Linux上编译安装的spec文件中的常用路径以及宏变量
  8. SVN共享链接时,避免使用服务器地址,要使用根目录(^)
  9. markdown 文档转 word
  10. Java面试题及答案整理(2022最新版)
  11. html5快手视频播放特效,抖音快手热门上人在天上飞的特效视频教程
  12. 电脑查看连接过的WiFi密码
  13. Windows安装Android软件,win7系统安装安卓软件WindowsAndroid的方法
  14. 怎么批量修改文件夹里照片的名字
  15. Linux如何才能ping通外网(详细设置过程,基于Qracle VM VirtualBox)
  16. FPGA数字信号处理(十一)ASK解调技术
  17. 70个JavaScript面试题集锦,内含解答,自测 JS 掌握程度
  18. 【2021】网络协议从入门到底层原理-MJ【新】附上下载链接
  19. 华为OBS通过ObjectKey生成临时的url地址
  20. OneKey Tools Lite插件安装常见问题集锦(PowerPoint版)

热门文章

  1. js正则表达式 - 验证11位手机号码、邮箱验证、18位身份证号码
  2. 网页特效代码集合+实例(C#)
  3. 评论:高盛喊冤是此地无银三百两
  4. android视频转场,两个视频怎么无缝衔接,在手机上将两个视频合并并在连接处加转场效果...
  5. Google Earth Engine ——GCOM-C 进行长期和持续的全球叶面积指数数据集(JAXA/GCOM-C/L3/LAND/LAI/V2)
  6. 【word】word跨页不断行问题
  7. 给用户的一封信:听说你要结婚了?
  8. 华为手机显示服务器繁忙,显示服务器繁忙
  9. 小猪的Python学习之旅 —— 18.Python微信转发小宇宙早报
  10. xgs芯片_了解有关XGS的所有信息