• C语言学习笔记02


    2024-02-29

    选择语句和循环语句

    选择语句:
    if esle 或switch

    # define _CRT_SECURE_NO_WARNINGS
    # include 
    
    int main()
    {
    	int input = 0;
    	printf("考研去哪里?\n");
    	printf("建筑学或者计算机0/1?\n");
    	scanf("%d", &input);
    
    	if (input == 1)
    	{
    		printf("建筑学");
    	}
    	else
    	{ 
    		printf("计算机");
    	}
    
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    循环语句:

    • while语句
    • for语句
    • do ……while 语句
    int main()
    {
    	printf("加入光荣的进化");
    	int line = 0;
    
    	while (line < 20000)
    	{
    		line++;
    		printf("已初步达到目标\n");
    	}
    	if (line >= 20000)
    	{
    		printf("继续加油");
    	}
    
    	else
    	{
    		printf("没有达到目标");
    	}
    	
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    C语言是结构化的程序设计语言

    • 顺序结构
    • 选择结构
    • 循环结构

    函数

    int Add(int x, int y)
    {
    	int z = 0;
    	z = x + y;
    	return z;
    
    }
    
    int main()
    {
    	int a = 0;
    	int b = 0;
    	scanf("%d %d", &a, &b);
    	int sum = Add(a, b);
    
    	printf("%d\n", sum);
    
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    int返回类型
    Add函数名
    int x,int y函数参数
    { }内为函数体

    数组

    int main()
    {
    	int arr[10] = { 10,12,45,15,15,88,22,88,2,52 };
    	int a = 0;
    	while (a < 10)
    	{
    		printf("%d ", arr[a]);
    		a = a + 1;
    	}
    
    	return 0;
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    全局变量和局部变量局部优先

    #操作符
    算数操作符
    + - * / %

    移位操作符
    >> <<

    位操作符
    & ^ |

    赋值操作符
    = += *= /= &= ^= |= <<= >>=

    单目操作符

    ! 逻辑反操作
    - 负值
    + 正值
    & 取地址
    sizeof 操作数得类型长度(以字节为单位)
    ~ 对一个数得二进制按位取反
    -- 前缀、后缀--
    ++ 前缀、后缀++
    * 间接访问操作符(解引用操作符)
    (类型) 强制类型转换
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    关系操作符

    >
    >=
    <
    <=
    != 用于测试"不相等"
    == 用于测试"相等"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    逻辑操作符

    && 逻辑与
    || 逻辑或
    
    • 1
    • 2

    条件操作符

    exp1 ? exp2 : exp3
    
    • 1

    逗号表达式

    exp1, exp2, exp3, ……expN
    
    • 1

    下标引用、函数调用和结构成员

    [] () . ->
    
    • 1

    常用关键字

    auto break extern float case for char goto sizeof stati struct double else const continue default do enum if int long register return short signed switch typedef union unsigned void volatile while
    
    • 1
  • 相关阅读:
    tensorflow2.x --------------------DenseNet-----------------------------
    高校教务系统登录页面JS分析——皖西学院
    Jmeter接口测试---随机数、加密、cookie鉴权、断言、CSV参数化
    【笔试刷题训练】day_13
    深度学习 | CNN卷积核与通道
    电子元器件的结温壳温与环境温度经验总结
    mac配置双网卡 mac同时使用内网和外网
    卷三 周纪三
    常用软件安装包
    [附源码]java毕业设计医药管理系统
  • 原文地址:https://blog.csdn.net/qq_52737339/article/details/136383228