1.入门

第一个C语言程序

#include <stdio.h>

int main()
{
    printf("hello,world .");
    return 0;
}

image-20210618021318913

注意 : 单独的反斜杠 是 下一行时上一行的组成部分

#include <stdio.h>

int main()
{
    print\
    f("hello , world\hello");
    return 0;
}

2.变量

  1. 英文字母 数字下划线组成 a-zA-Z 0-9 _

  2. 字母下划线开头

  3. 变量名区分大小写

  4. 避开关键字

    image-20210618022059305

    44个关键字,C11标准

3.数据类型

  • char 字符型 一个字节

  • int 整型 所用机器整数的最自然长度

  • float 单精度浮点型

  • double 双精度浮点型

  • _Bool 布尔类型enum

  • enum枚举类型

  • 声明变量

    #include<stdio.h>
    int main()
    {   
        int a;
        char b;
        float c;
        double d;
    
        a = 520;
        b = 'f'; #注意是单引号
        c= 3.14;
        d = 3.1415269853;
        printf("hello world年度%d\n",a);
        printf("hello world is %cish\n",b);
        printf("I love %c ishC.com!\n", b);
        printf("圆周率是%.2f\n",c);
        printf("圆周率精确到小数点9位是%11.9f\n",d);
        return 0;
    }
    
  • sizeof运算符,数据类型货表达式的长度

    printf("我的url是%d\n",sizeof(a));

    image-20210618024905201

  • 手打

4.常量

image-20210618023616753

  • 定义常量

    格式 : #define 标识符 常量

    image-20210618023800983

    标识符的命名和变量规则一致,一般都全大写

    image-20210618024310084

    会在后面加一个\0

5.运算符

  • 算数运算符

    image-20210618025903835

  • 关系运算符, == !=

  • 逻辑 !非 &&与 ||或

    短路求值: 只有单第一个操作数无法确定逻辑值时,才会第二个运算数进求职

    image-20210618030954226

    0 3 1 3

  • if分支

posted on 2022-05-27 15:36  啊,那逝去的青春  阅读(20)  评论(0编辑  收藏  举报