当前位置:网站首页>C语言从入门到入土(一)
C语言从入门到入土(一)
2022-07-24 05:16:00 【泡泡牛奶】
1、第一个C语言程序
学习C语言首先要知道C语言的基础框架
这是标准C语言标准的主函数写法(需要牢记)
#include <stdio.h>
int main()
{
//语句
return 0;
}而在有一些书本上会看到下面两种写法
#include <stdio.h>
void main()
{
//语句
}#include <stdio.h>
main()
{
//语句
}这些都是比较早期的写法,可以认识一下
理解:c语言是以个房子,main函数相当是一扇大门(主门),PS:会有侧门(这个相当于自定义函数),但要使用这些侧门,总要先踏入主门吧
2、数据类型
| 类型 | 表示 | 所访问的字节大小 单位 ( 比特 - bit - B) | 输出格式 |
| char | 字符型 | 1 | %c / %s (字符串) |
| short | 短整型 | 2 | %hd |
| int | 整型 | 4 | %d |
| long | 长整型 | 4 | %ld |
| long long | 长长整型 | 8 | %lld |
| float | 单精度浮点型 | 4 | %f |
| double | 双精度浮点型 | 8 | %lf |
在早期学习C语言的时候主要认识这些就可以了
3、常量与变量
3.1、什么是 常量?变量?
(1)常量
在C语言中,经常用不变的值来表示常量
例如:
3.14;
2022;
666;(2)变量
同理,在C语言中,随时可能会变的值就是变量
在C语言中,要使用变量,首先要知道你将要使用的变量的类型,然后再为这个变量取个名字
例如:
int i; //定义的是一个 类型为 整型 ,名字为 i 的变量
char ch;//定义的是一个 类型为 字符型 ,名字为 ch 的变量3.2、定义变量的表示方法
int i = 1;//为 变量i 初始化为 1
char ch = 'a';//为 变量ch 初始化为字符 a3.3、变量的分类
(1)全局变量
理解:在 大括号 { } 外面的变量就是全局变量
(2)局部变量
理解:在 大括号 { } 里面的变量就是局部变量
(3)注意:
1、变量必须在前面(无论是全局还是局部)
2、同一个变量名不能重复定义
3、当全局变量的名字与局部变量的的名字相同时,优先局部变量
示例如下:

结语
好啦,本期就到这里,希望大家都能实现自己的目标,好好加油,努力实现更上一层,我们下期再见,拜拜

边栏推荐
- Do you want to have a robot that can make cartoon avatars in three steps?
- 跟李沐学ai 线性回归 从零开始的代码实现超详解
- MySQL连接
- C语言实现扫雷游戏
- 泛型和注解
- 1. Input a 100 point score from the keyboard and output its grade according to the following principles: score ≥ 90, Grade A; 80 ≤ score < 90, grade B; 70 ≤ score < 80, grade C; 60 ≤ score < 70, grade
- T 11-20
- C语言入门篇 二.函数
- Skills of BeanShell dealing with JSON
- Scikit learn -- steps of machine learning application development
猜你喜欢

DNS domain name resolution service

JMeter FAQs
![Knowledge record of College Physics C in advance in summer [update]](/img/c4/76b669c3229a365a5e2567f7fb824e.png)
Knowledge record of College Physics C in advance in summer [update]

C语言进阶篇 六.文件的操作

c2-随机产生函数种子seed、numpy.random.seed()、tf.random.set_seed学习+转载整理

The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands

OSS文件上传

C语言入门篇 三.数组 四.操作符

T 1-5

The world's first large aerospace model came out. Wenxin's second supplement "Fuchun Mountain Residence map" is Baidu Pratt Whitney AI's perseverance
随机推荐
【sklearn】RF 交叉验证 袋外数据 参数学习曲线 网格搜索
Echo speaker pairing and operation method
Source code compilation!!
C语言入门篇 二.函数
MySQL深入了解
[basic 8] - processes and threads
C语言进阶篇 五.动态内存管理
On the dilemma faced by non transferable reputation points NFT SBTS
明星逆市入局的NFT,如何能走出独立行情?
反射的介绍
[basic 7] - exceptions, capture and customize exceptions
T 11-20
SSM整合
九大排序实现与比较(万字总结)
MySQL insight
C语言实现扫雷游戏
Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]
修改jupyter保存路径
finally和return的执行顺序
Scikit learn -- steps of machine learning application development