当前位置:网站首页>初识C语言(上)
初识C语言(上)
2022-07-06 09:19:00 【犇犇犇犇犇犇】
在这里我将给大家简单介绍一下C语言我们要学的内容,大家进行初步的认知。
C语言呢是一门结构化程序设计语言,什么是结构化,也就是:顺序结构,选择结构,循环结构,生活中的所有事都是这几个结构的组合嵌套和重复。所以C语言才能通过编程解决生活中的问题。
编程语言的发展:机器语言也就是二进制–汇编语言人们通过一些助记符更好的编程–B语言–C语言,这时C语言已经是一门高级语言了。
C语言中我们要了解
- 变量
- 常量
- 数据类型
- 变量的作用域和生命周期
- 注释和转义字符
- 关键字
- 数组
- 函数
- 指针
- 选择结构
- 循环结构
- 结构体
变量和常量
看下面一段代码
//1.字面常量
//2.const修饰的常变量
//3.通过define定义的常量
//4.枚举定义的常量
enum Color
{
Red=0,
Green=0,
Blue=0,
};
#define Max 100
int main()
{
//30;
//3.14;
//'W';//字符
//"abc";
在C语言中,const修饰的a,本质是变量,但是不能直接修改,有常量的性质
//const int a = 10;
//a = 20;
//printf("%d ", a);
//const int n = 10;
//int arr[n] = { 0 };//这时会显示错误为表达式中必须含有常量值
//return 0;
//Max = 10;//当你想修改define定义的变量值时,就会报错。
//printf("%d\n", Max);
//Red = 10; //可以看到会出现和define同样的报错
printf("%d\n", Red);
return 0;
}
int main()
{
int a = 10;
a = 20;
printf("%d\n", a);
//这就是变量是可以改变的值
return 0;
}
数据类型
//数据类型有哪些
//字符
//整型 短整型 整型 长整型 更长整型
//浮点型 单精度浮点型 双精度浮点型
int main(){
printf("%d\n", sizeof(char));// 字节 --1
printf("%d\n", sizeof(short));// --2
printf("%d\n", sizeof(int));// --4
printf("%d\n", sizeof(long));// --4
printf("%d\n", sizeof(long long));// --8
printf("%d\n", sizeof(float));// --4
printf("%d\n", sizeof(double));// --8
return 0;
}
变量的生命周期和作用域
//变量的作用域
//1.局部变量
//从创建它的函数开始到这个函数结束
//2.全局变量
//全局变量的作用域是整个工程
//变量的生命周期
//局部变量:进入作用域开始,出作用域结束
//全局变量:整个程序的生命周期
int main(){
int a = 10;
{
//int a = 10;
printf("%d\n", a);
}
printf("%d", a);
return 0;
}
注释和转义字符
/* /* int main() { 这是C语言的注释风格 */
return 0;
}*/
//int main()
//{
// 这是C++的注释风格
// return 0;
//}
//现在的C语言中也引入了 //这种风格
/**/C语言的这种注释风格
缺点:不能嵌套使用
C++的注释风格
优点:方便单行注释,也可以多行注释
转义字符大家自己上网搜一下了解就可以了这里就不过多介绍,但是给大家留下一道题,看看是否能做对
int main()
{
//编译器会输出什么
printf("%s\n","C:\\test\test.c");
printf("%d\n", sizeof("C:\\test\test.c\x069"));
return 0;
}
数组
int main()
{
int arr[10] = {
0 };
// int 代表数组类型 arr表示数组名
//10--数组大小 {0}---数组内的十个元素全部赋值为零
return 0;
}
函数
//写一个两数之和
int ADD(int x, int y)
{
//int 函数的返回类型
//ADD 函数名
//int x,int y 函数的参数
//{
// return x + y; 这三行是函数体
//}
return x + y;
}
int main(){
//创建
int num1 = 0;//变量初始化
int num2 = 0;
//输入
scanf("%d %d", &num1, &num2);
//求和
//int sum = num1 + num2;
int sum = ADD(num1, num2);
//输出
printf("%d", sum);
return 0;
}
未完待续…
边栏推荐
- KF UD分解之UD分解基础篇【1】
- Fairygui character status Popup
- How to improve the deletion speed of sequential class containers?
- 阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
- 错误: 找不到符号
- Record: solution of 404 error of servlet accessing database in dynamic web project
- Mixed use of fairygui button dynamics
- Combination of fairygui check box and progress bar
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- 系统设计学习(三)Design Amazon‘s sales rank by category feature
猜你喜欢
[算法] 剑指offer2 golang 面试题2:二进制加法
FairyGUI循環列錶
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Problems and solutions of robust estimation in rtklib single point location spp
阿里云微服务(三)Sentinel开源流控熔断降级组件
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
Novatel board oem617d configuration step record
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Fgui project packaging and Publishing & importing unity & the way to display the UI
随机推荐
Record: I accidentally wrote a recursion next time
如何保障 MySQL 和 Redis 的数据一致性?
Fundamentals of UD decomposition of KF UD decomposition [1]
Fairygui loop list
Lean product development - Lean Software Development & lean product development
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
闇の連鎖(LCA+树上差分)
Answer to "software testing" exercise: Chapter 1
服务未正常关闭导致端口被占用
Fairygui gain buff value change display
Basic DOS commands
抗差估计在rtklib的pntpos函数(标准单点定位spp)中的c代码实现
[算法] 剑指offer2 golang 面试题1:整数除法
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
All in one 1405: sum and product of prime numbers
[GNSS] robust estimation (robust estimation) principle and program implementation
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Knowledge system of digital IT practitioners | software development methods -- agile
2022 National Games RE1 baby_ tree
Mysql database index