C语言_数据类型,运算符,表达式

打印 Hello world

hello.c

#include<stdio.h>

int main()
{
        printf("hello world \n");
}

cc 编译,并指定编译名

cc hello.c -o hello

在这里插入图片描述
或者 使用 ANSI(American National Standards Institute.) 编译

cc -ansi hello.c -o hello

运行

./hello

在这里插入图片描述

常量与变量

符号常量

#include<stdio.h>

#define PRICE 30

int main(){
        int num,total;
        num = 10;
        total = num * PRICE;
        printf("total=%d \n",total);
}

在这里插入图片描述

数据类型

整型数据

整型变量的定义与使用

#include<stdio.h>
int main(){
        int a,b,c,d;
        unsigned u;
        a=12; b=-24; u=10;
        c=a+u; d=b+u;
        printf("a+u=%d, b+u=%d \n",c,d);
}

在这里插入图片描述
整理变量的溢出

#include<stdio.h>
int main(){
        int a,b;
        a = 32767;
        b = a+1;
        printf("a=%d, b=%d \n",a,b);
}

在这里插入图片描述

实型数据

实型数据的舍入误差

#include<stdio.h>
int main(){
        float a,b;
        a = 123456.789e5;
        b = a + 20;
        printf("%f \n",a);
        printf("%f \n",b);
}

1.0/3*3 结果并不等于1

#include<stdio.h>
int main(){
        float a;
        double b;
        a = 33333.33333;
        b = 33333.33333333333333;
        printf("%f \n%f \n",a,b);
}

在这里插入图片描述

字符型数据

转义字符

转义字符含义ASCII代码
\n回车换行10
\t横向调到下一制表位置9
\b退格8
\r回车13
\f走纸换页12
\\反斜线符\92
\'单引号符39
\''双引号符34
\a鸣铃7
\ddd1~3位八进制数所代表的字符
\xhh1~2为十六制数所代表的字符
#include<stdio.h>
int main(){
    int a,b,c;
    a=5; b=6; c=7;
    printf("  ab  c\tde\rf\n");
    printf("hijk\tL\bM\n");
}

在这里插入图片描述

强制类型转换

(类型说明符)(表达式)

#include<stdio.h>
int main(){
	float f=5.75;
    printf("(int)f=%d, f=%f \n",(int)f,f);
}

在这里插入图片描述

算术运算符和算术表达式

自增,自减运算符

++ii自增1后再参与其他运算
--ii自减1后再参与其他运算
i++i参与运算后,i的值再自增1
i--i参与运算后,i的值再自减1
#include<stdio.h>
int main(){
    int i = 8;
    printf("++i %d\n",++i);
    printf("--i %d\n",--i);
    printf("i++ %d\n",i++);
    printf("i-- %d\n",i--);
    printf("-i++ %d\n",-i++);
    printf("-i-- %d\n",-i--);
}

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值