#include <stdio.h>标签:count,return,int,study,3.15,3.16,++,printf,-- From: https://blog.51cto.com/u_15929197/6126054
/*
int main()
{//数组内容交换
int arr1[] = { 1,3,5,7,9 };
int arr2[] = { 2,4,6,8,0 };
int tmp = 0;
int i = 0;
int sz = sizeof(arr1) / sizeof(arr1[0]);
for (i = 0; i < sz; i++)
{
tmp = arr1[i];
arr1[i] = arr2[i];
arr2[i] = tmp;
printf("%d arr1:%d arr2:%d\n", i, arr1[i], arr2[i]);
}
return 0;
}
*/
/*
int main()
{
int arr[] = {1,2,3,4,5};//int*是4个字节
short* p = (short*)arr;//short*只能访问两个字节
int i = 0;
for (i = 0; i < 4; i++)
{
*(p + i) = 0;//仅修改了1-->0000 2-->0002
}
for (i = 0; i < 5; i++)
{
printf("%d ",arr[i]);//00345
}
return 0;
}
*/
/*
int main()
{
int a = 0x11223344;//存储为 44 33 22 11,两个字节存放一起
char* pc = (char*)&a;
*pc = 0;//仅能操作一个字节即内存为00 33 22 11
printf("%x\n",a); //11223300
return 0;
}
*/
/*
int i;//全局变量--若不初始化,默认为0
int main()
{
i--;//i=-1 -->10000000000000000000000000000001原码
//11111111111111111111111111111110反码
//11111111111111111111111111111111补码-->很大的数>4-->sizeof(i)
if (i > sizeof(i))//sizeof--计算变量/类型所占内存的大小 >=0 无符号数
{
printf(">\n");
}
else
{
printf("<\n");
}
//>
return 0;
}
*/
/*
int main()
{
int a, b, c;
a = 5;
c = ++a;//先++后赋值给c,即a=a+1,c=a
//c=6 a=6
b = ++c, c++, ++a, a++;//c=c+1,c=c+1,a=a+1,b=a++-->b=a,a=a+1
//c=8,a=8,b=7
//逗号表达式,从左到右计算,最后一个逗号内的赋值给等号前的
b += a++ + c;//b=b+a+c,a++
//+的优先级高于++ ,a=9 c=8,b=23
printf(" a=%d\n b=%d\n c=%d\n",a,b,c);
return 0;
}
*/
/*
int count_bit_one(int a)
{
int count = 0;
while (a)
{
if (a % 2 == 1)
{
count++;
}
a = a / 2;
}
return count;
}
//只适用于正数
int main()
{//求a的2进制表示中有几个1
int a = 0;//e.g. 13-->0000000000000000000000001101
scanf("%d",&a);
int count = count_bit_one(a);
printf("count= %d\n",count);
return 0;
}
*/
/*
int count_bit_one(unsigned int a)//使用无符号数unsigned int 避免负数影响结果
{
int count = 0;
while (a)
{
if (a % 2 == 1)
{
count++;
}
a = a / 2;
}
return count;
}
//只适用于正数
int main()
{//求a的2进制表示中有几个1
int a = 0;//e.g. 13-->0000000000000000000000001101
scanf("%d", &a);
int count = count_bit_one(a);
printf("count= %d\n", count);
return 0;
}
*/
/*
int count_bit_one(int a)//使用无符号数unsigned int 避免负数影响结果
{
int count = 0;
int i = 0;
for(i = 0; i < 32; i++)
{
if ((a >> i) & 1 == 1)
count++;
}
return count;
}
//只适用于正数
int main()
{//求a的2进制表示中有几个1
int a = 0;//e.g. 13-->0000000000000000000000001101
scanf("%d", &a);
int count = count_bit_one(a);
printf("count= %d\n", count);
return 0;
}
*/
/*
int count_bit_one(int a)//使用无符号数unsigned int 避免负数影响结果
{
int count = 0;
while (a)
{
a = a & (a - 1);//每进行1一次消去一个1
//a=13 1101
//a-1 1100
//新a 1100 count=1
//新a-1 1011
//新新a 1000 count=2
//新新a-1 0111
//新新新a 0000 count=3
count++;
}
return count;
}
//只适用于正数
int main()
{//求a的2进制表示中有几个1
int a = 0;//e.g. 13-->0000000000000000000000001101
scanf("%d", &a);
int count = count_bit_one(a);
printf("count= %d\n", count);
return 0;
}
*/
/*
int get_diff_bit(int a, int b)
{
int tmp= a^b;
int count = 0;
while (tmp)
{
tmp = tmp & (tmp - 1);
count++;
}
return count;
}
int main()
{//求二进制中不同位的个数
int a = 0;
int b = 0;
scanf("%d%d", &a, &b);
int count = get_diff_bit(a, b);
printf("%d\n",count);
return 0;
}
*/