第五章-算术运算符

------------恢复内容开始------------

 1.  目

单目和双目

操作几个对象,1个对象就是单目,2个对象就是双目

+

-

*

/

和Python里面一样

2. 优先级

求一个平方,这里c语言和python的区别

root@ubuntu:/home/yanyanzhang/c_study/p9# nl t1.c 
     1    #include<stdio.h>
     2    #include<math.h>
       
       
     3    int main()
     4    {
     5        
     6        int x,y,ret;
     7        x = 2;
     8        y = 3;
     9        ret = pow(2,3);  # 这里如果换成 ret = pow(x,y) 编译运行直接报错,collect2: error: ld returned 1 exit status
10        printf("result is %d
",ret);
    11        return 0;
       
    12    }


结果
root@ubuntu:/home/yanyanzhang/c_study/p9# cc t1.c -o t1 && ./t1
result is 8

难道pow函数里面不能使用引用吗?  # TODO

3. 类型转换

2 + 3.0

编译器的逻辑是,将占用内存小的转换成占用内存大的类型,统一输出内存大的类型,因此结果是浮点型

int a = 2;
double b = 3.0;
double c = a + b;
printf("ret is %1f
",c);


结果是:ret is 5.000000

为什么 ret的结果小数点后保留了6位小数?

# TODO

------------恢复内容结束------------

原文地址:https://www.cnblogs.com/meloncodezhang/p/14466616.html