3.19study

时间:2021-02-10 01:01:50
#include <stdio.h>

/*
int Add(int x, int y)
{
int z = 0;
z = x + y;
return z;
}
int main()
{
int a = 10;//先压栈的后使用
int b = 20;//后压栈的先使用 ----类似子弹夹
int ret = 0;
ret = Add(a, b);//传参先传b后传a

return 0;
}
*/

/*
int main()
{
int a = 20;
//00000000000000000000000000001010--原码
//00000000000000000000000000001010--反码
//00000000000000000000000000001010--补码
//0x00000014--HEX
int b = -10;
//10000000000000000000000000001010--原码
//11111111111111111111111111110101--反码
//11111111111111111111111111110110--补码
//0xFFFFFF6--HEX
return 0;
}
*/

/*
int main()
{
//1 - 1;
int a = 0x11223344; //先F10,调试-->窗口-->内存监视
//1+(-1)
//若用原码计算则=-2
//采用补码计算
//00000000000000000000000000000001 --正数原反补相同
//11111111111111111111111111111111 -- -1的补码
//00000000000000000000000000000000
return 0;
}
*/

/*
int main()
{//设计一个程序判断当前字节序
int a = 1;
char* p = (char *)&a;
if (*p == 1)
{
printf("小端\n");
}
else
{
printf("大端\n");
}
return 0;
}
*/

/*
int check_sys()
{
int a = 1;
char*p = (char*)&a;
//返回1,小端
//返回0,大端
return *p;
}

int main()
{//设计一个程序判断当前字节序
int ret=check_sys();
if (ret == 1)
{
printf("小端\n");
}
else
{
printf("大端\n");
}
return 0;
}
*/

/*
int main()
{
int a = 0x11223344;
// int *p = &a;//指针类型决定了访问几个字节,int 访问四个字节
// *p = 0;
char* p = &a;//char访问1个字节
*p = 0;

return 0;
}
*/

/*
int main()
{
char a = -1;
//内存中存储的补码:11111111111111111111111111111111
//只能存8个比特位即11111111-->整形提升-->11111111111111111111111111111111
signed char b = -1;
//11111111-->整形提升-->11111111111111111111111111111111
unsigned char c = -1;//无符号数-->符号位为0
//11111111-->整形提升-->00000000000000000000000011111111
printf("a=%d b=%d c=%d",a,b,c);//-1 -1 255
//
return 0;
}
*/

/*
int main()
{
char a = -128;
char b = 128;//127+1
//10000000000000000000000010000000 -->原码
//11111111111111111111111110000000 -->补码
//存放于a中-->10000000
//整形提升后11111111111111111111111110000000
printf("%u\n",a);//%u -->打印十进制的无符号数字
printf("%u\n",b);
//由于%u认定存放于内存的为无符号数,故原反补相同,直接打印
//%d -->打印十进制有符号数
return 0;
}
*/

/*
int main()
{
int i = -20;
//10000000000000000000000000010100--原码
//11111111111111111111111111101011--反码
//11111111111111111111111111101100--补码
unsigned int j = 10;
//00000000000000000000000000001010--原反补
printf("%d\n",i+j);//-10
//11111111111111111111111111110110--结果(补码)
//11111111111111111111111111110101--反码
//10000000000000000000000000001010--原码(打印出的结果)
return 0;
}
*/

/*
int main()
{
unsigned int i;//i为无符号数,最小为0,故一直满足for循环
for (i = 9; i >= 0; i--)
{
printf("%u\n", i);//死循环
}


return 0;
}
*/

/*
int main()
{
//char表示范围-128~127
char a[1000];//0~999
int i;
for (i = 0; i < 1000; i++)
{
a[i] = -1 - i;// -1,-2,-3,...-127,-128,127,126,125,....3,2,1,0-->为截止位,故有128+127位=255
} //-128时再-1为-127即1000000000000000000 -1-->011111111111111111111
printf("%d",strlen(a));//255 \0的ASCII码为0

return 0;
}
*/


/*
unsigned char i = 0;//0~255
int main()
{
for (i = 0; i <= 125; i++)//i的取值永远成立,故为死循环
{
printf("hello world\n");//死循环
}

return 0;
}
*/

/*
int main()
{
double d = 1E10;
printf("%lf\n",d);

return 0;
}
*/

int main()
{
int n = 9;
float* pFloat = (float*)&n;
printf("n的值为:%d\n",n);//9
printf("*pFloat的值为:%f\n",*pFloat);//0.000000

*pFloat = 9.0;
printf("num的值为:%d\n", n);//1091567616
printf("*pFloat的值为:%f\n", *pFloat);//9.000000

return 0;
}

相关文章