2

C studing NO.4 操作符1

 2 years ago
source link: https://blog.51cto.com/u_15756673/5623656
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

C studing NO.4 操作符1

精选 原创

计算机小腊鸡 2022-08-26 13:27:26 ©著作权

文章标签 操作符 数组 算术操作符 文章分类 IT业界 其它 阅读数174

1、算术操作符

+ - * / %   加减乘除取余

int main()
{
//int a = 9 / 2; //a=4 取整
//printf("%d\n", a);
//float a = 9 / 2; //a=4.000000
//printf("%f\n", a);
//float a = 9 / 2.0; //a=4.500000
//printf("%f\n", a);
//int a = 9 % 2; //a=1 取余
//printf("%d\n", a);
return 0;
}

2、移位操作符

<<   >>

int main()
{
int a = 1;
int b = a<< 2;
printf("%d\n", b);
return 0;
}

3、位操作符

& (与)          ^ (异或)                |(或)

4、赋值操作符

=   +=   -+  *=  &=   ^=   |=  <<=   >>=

5、单目操作符 

!  逻辑反操作

—  负值

+正值

&取地址

sizeof操作数的类型长度(以字节为单位)

~对一个数的二进制位取反

--前置、后置--

++前置、后置++

*间接访问操作符(解引用操作符)

(类型)强制类型转换

int main()
{
//0表示假,非0就表示真
int a = 0;
printf("%d\n", !a);//!a=1
if (a)
{
printf("%s\n", "abc");
//如果a为真 做事
}
if (!a)
{
printf("%s\n", "def");
//如果a为假 做事
}
return 0;
}
int main()
{
//sizeof是一个操作符
//不是函数
//计算类型或者变量大小

int a = 10;
printf("%d\n", sizeof(int));
printf("%d\n", sizeof(a));
return 0;
}
int main()
{
int arr[10] = {0};
printf("%d\n", sizeof(arr));//计算数组的总大小10数组×4个字节
printf("%d\n", sizeof(arr[0]));//计算数组中单个大小
int sz = sizeof(arr) / sizeof(arr[0]);
printf("%d\n", sz);
return 0;
}
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK