發現記憶力越來越差,所以干脆搞這麼一個東西,就是把C語言的最常用的語法匯編在一起,不斷完善。這樣以後只要經常把這個回顧一下就可以了。不然去翻書太多了。。。
f.h
#define Area 1000 struct student{ char *last_name; int student_id; char grade; int a; };
h.c
#include <stdio.h> #include "f.h" #define PI 3.1415926 #define LIMIT 20 struct employee_data { int a; }; int main(void) { //引用 printf("%d\n",Area); //字符 char c; c='A'; int age; char first,end; printf("%c\n",c); printf("%3c\n",c); printf("%3c\n",'A'); //scanf("%d",&age); //printf("%d\n",age); //scanf("%c",&first); //printf("%c\n",first); char *p1; p1=&c; printf("%c%d%c\n",*p1,*p1+1,*p1+2); //printf("%c",'\a');//響鈴 //char d=getchar();//putchar() //printf("%c\n",d); const int p_sea=20; //p_sea=30;會報錯,向只讀變量賦值 float x,y; x=2.0; y=3.0; printf("%f\n",x*y); printf("%f\n",PI); double d1=1.123456789; printf("%lf\n",d1); int i=1,sum=0; while (i<7){ sum=sum+i; i++; } printf("%d\n",sum); int sz[3]={23,15,78}; sz[1]=2; printf("%d\n",sz[1]); //求數組長度 int count=sizeof(sz)/sizeof(int); printf("%d\n",count); typedef int myint; myint i1=9; printf("%d\n",i1); printf("%d\n",sizeof(i1));//輸出4 int是4位 //指針和數組關系 int sz1[4]={40,82,67,11}; int *p; p=sz1; printf("*p %d\n",*p);//40 printf("*p+1 %d\n",*p+1);//41 printf("*p+2 %d\n",*p+2);//42 printf("*p %d\n",*p);//40 printf("*p+1 %d\n",*(p+1));//82 printf("*p+2 %d\n",*(p+2));//67 struct card{ int pips; char suit; }c1,c2; c1.pips=3; c1.suit='5'; c2=c1; printf("struct c2.pips: %d\n",c2.pips); typedef struct{ int re; int im; }complex; complex as,ac[2]; as.re=89; ac[0].re=1; ac[1].re=2; printf("struct ac[0].re: %d\n",ac[0].re); printf("struct ac[1].re: %d\n",ac[1].re); printf("struct ac[0].re: %d\n",ac[0].re); struct student tmp; tmp.last_name="Canada"; tmp.grade='A'; tmp.student_id=122; tmp.a=0; printf("struct tmp.last_name: %s\n",tmp.last_name); struct employee_data e1; e1.a=12; int e11=getdata(e1); printf("struct e11: %d\n",e11); int e12=getdata_add(&e1); printf("struct e12: %d\n",e12); //與或非 int y1=3; int y2=0; int y3=y1&y2; printf("y3 &: %d\n",y3); printf("-9 >>31: %d\n",abs(-9)); #undef __FD_SETSIZE #define __FD_SETSIZE 1024 printf("#define: %d\n",__FD_SETSIZE); return 0; } //一個負數右移31位後會變成 0xffffffff,一個正數右移31位則為 0x00000000 //0xffffffff ^ a + a = - 1 //因為 1011 ^ 1111 = 0100 異或1111其實是把a的0和1進行了顛倒。 int abs(int x) { return (x ^ (x >> 31)) - (x >> 31); } int getdata(struct employee_data e) { return e.a; } int getdata_add(struct employee_data *e) { return e->a; }