【C语言】学习


前言

`以后要学习操作系统+深度学习了,所以C语言就不可缺少了。


1. warm up

1.1 输出helloworld

#include<stdio.h>
void main() {
	printf("Hello World!!");
}

std = 标准
io=输入输出
.h = help .是一种风格
include <stdio.h>: 编译系统在系统头文件所在目录搜索包含头文件stdio.h
include “stdio.h”:编译系统首先在源文件目录中查找stdio.h,找不到转系统文件所在目录搜索

“stdio.h” 表示优先级是用户的级别高,找不到再找系统的。

1.2 示例

从键盘输入一个整数,若其值小于0,输出-1,等于0,输出0,大于0,输出1

#include<stdio.h>
void main(){
	int x; //定义整数变量
	scanf("%d", &x);
	if (x < 0)
		printf("\n -1 \n");
	else if(x == 0)
		printf("\n 0 \n");
	else (x > 0)
		printf("\n 1 \n");
}

求1到100的和

#include<stdio.h>
void main() {
  int i = 1, s = 0;
  while(i<=100) {
  	 s = s + 1;
  	 i = i + 1;
  }
  printf("sum=%d\n",s);
}

printf(s) 是错误的, 是伪代码,经常会遇见,但最简单的可运行代码也需要printf(“%d”,s);

1.3 C语言程序结构

预处理:编译时进行的处理,比如包含、宏 #include, #define
函数
变量定义 格式, 类型 sizeof(int) 可以知道所占字节数,影响取值范围.
语句组
注释
在这里插入图片描述

Supongo que te gusta

Origin blog.csdn.net/weixin_40293999/article/details/130475631
Recomendado
Clasificación