#include<stdio.h>
//int main() //{ //?? ?int a = 0; //?? ?printf("%d\n", ~a);//答案为-1 //?? ?//~把二进制中的数字,1变0,0变1 //?? ?//00000000000000000000000000000000 //?? ?//~ //?? ?// 在计算机的中储存的是补码 //?? ?//11111111111111111111111111111111原码 //?? ?//10000000000000000000000000000000反码 //?? ?//反码+1=补码 //?? ?//10000000000000000000000000000001补码 //?? ?//即为-1 //?? ?return 0; //} //int main() //{ //?? ?int a = 10; //?? ?int b = a++; //?? ?int a2 = 10; //?? ?int b2 = ++a2; //?? ?//a++和++a的区别 //?? ?//a++先使用,再++ //?? ?//++a先++,再使用 //?? ?printf("%d\n", a); //?? ?printf("%d\n", b); //?? ?printf("%d\n", a2); //?? ?printf("%d\n", b2); //?? ?return 0; //} //int main() //{ //?? ?int a = (int)3.14; //?? ?//这里的(int)为强制类型转化,不推荐使用 //?? ?printf("%d\n", a); //?? ?return 0; //} //&&与 //||或 //int main() //{ //?? ?int a = 0; //?? ?int b = 1; //?? ?int c = a > b ? a : b; //?? ?printf("%d\n", c); //?? ?return 0; //} //exp?exp1:exp2 //exp成立输出exp1,否则就是exp2
//int main() //{ //?? ?register int a = 0; //?? ?//register建议把a=0放在寄存器里面,速度快 //?? ?return 0; //} //typedef unsigned int u_int; //int main() //{ //?? ?u_int a = 0; //?? ?return 0; //} //typedef类型的重定义 //void test() //{ //?? ?static int a = 1; //?? ?//static改变了局部变量的生命周期 //?? ?a++; //?? ?printf("%d\n", a); //} //int main() //{ //?? ?int i = 1; //?? ?while (i < 10) //?? ?{ //?? ??? ?test(); //?? ??? ?i++; //?? ?} //?? ?return 0; //} extern int g_val; extern 声明外部符号 static修饰的全局变量,只能在自己所在的源文件使用 //int main() //{ //?? ?printf("%d\n", g_val); //?? ?return 0; //} //define定义宏 //#define ADD(X,Y) ((X)+(Y)) //int main() //{ //?? ?printf("%d\n", 4 * ADD(3, 4)); //?? ?return 0; //} //int main() //{ //?? ?int a = 10; //?? ?printf("%p\n", &a);//%p打印十六位,&取地址 //?? ?int* pa = &a;//*说明pa是指针变量 //?? ?char ch = 'w'; //?? ?char* pch = &ch; //?? ?printf("%p\n", pch); //?? ?return 0; // //} //int main() //{ //?? ?int a = 10; //?? ?int* pa = &a; //?? ?*pa = 20; //?? ?printf("%d\n", a); //?? ?return 0; //}//通过a的地址pa来改变a //int main() //{ //?? ?printf("%d\n", sizeof(char*)); //?? ?printf("%d\n", sizeof(short*)); //?? ?printf("%d\n", sizeof(int*)); //?? ?printf("%d\n", sizeof(long*)); //?? ?printf("%d\n", sizeof(long long*)); //?? ?printf("%d\n", sizeof(float*)); //?? ?printf("%d\n", sizeof(double*)); //?? ?return 0; //}//指针大小都是一样的,只和操作系统有关系
struct stu { ?? ?char name[20]; ?? ?int age; ?? ?int score; }; int main() { ?? ?struct stu s= ?? ?{ ?? ??? ?"张三",20,90 ?? ?}; ?? ?struct stu* ps = &s; ?? ?printf("1:%s %d %d\n", s.name, s.age, s.score);//结构体的创建和初始化 ?? ?printf("2:%s %d %d\n", (*ps).name, (*ps).age, (*ps).score); ?? ?printf("3:%s %d %d\n", ps->name, ps->age, ps->score); ?? ?return 0; }
|