C语言九阴真经

http://blog.csdn.net/21aspnet/article/details/7358153


发现记忆力越来越差,所以干脆搞这么一个东西,就是把C语言的最常用的语法汇编在一起,不断完善。这样以后只要经常把这个回顾一下就可以了。不然去翻书太多了。。。

 

f.h

[cpp]  view plain copy
  1. #define Area 1000    
  2. struct student{  
  3. char *last_name;  
  4. int student_id;  
  5. char grade;  
  6. int a;  
  7. };  



h.c

[cpp]  view plain copy
  1. #include <stdio.h>   
  2. #include "f.h"  
  3. #define PI 3.1415926  
  4. #define LIMIT 20  
  5. struct employee_data  
  6. {  
  7. int a;  
  8. };  
  9.   
  10.   
  11. int main(void)  
  12. {  
  13. //引用  
  14. printf("%d\n",Area);  
  15.   
  16. //字符  
  17. char c;  
  18. c='A';  
  19. int age;  
  20. char first,end;  
  21. printf("%c\n",c);  
  22. printf("%3c\n",c);  
  23. printf("%3c\n",'A');  
  24. //scanf("%d",&age);  
  25. //printf("%d\n",age);  
  26. //scanf("%c",&first);  
  27. //printf("%c\n",first);  
  28.   
  29. char *p1;  
  30. p1=&c;  
  31. printf("%c%d%c\n",*p1,*p1+1,*p1+2);  
  32. //printf("%c",'\a');//响铃  
  33. //char d=getchar();//putchar()  
  34. //printf("%c\n",d);  
  35.   
  36. const int p_sea=20;  
  37. //p_sea=30;会报错,向只读变量赋值  
  38. float x,y;  
  39. x=2.0;  
  40. y=3.0;  
  41. printf("%f\n",x*y);  
  42. printf("%f\n",PI);  
  43. double d1=1.123456789;  
  44. printf("%lf\n",d1);  
  45.   
  46. int i=1,sum=0;  
  47. while (i<7){  
  48. sum=sum+i;  
  49. i++;  
  50. }  
  51. printf("%d\n",sum);  
  52.   
  53. int sz[3]={23,15,78};  
  54. sz[1]=2;  
  55. printf("%d\n",sz[1]);  
  56.   
  57. //求数组长度  
  58. int count=sizeof(sz)/sizeof(int);    
  59. printf("%d\n",count);  
  60.   
  61. typedef int myint;  
  62. myint i1=9;  
  63. printf("%d\n",i1);  
  64. printf("%d\n",sizeof(i1));//输出4 int是4位  
  65.   
  66. //指针和数组关系  
  67. int sz1[4]={40,82,67,11};  
  68. int *p;  
  69. p=sz1;  
  70. printf("*p %d\n",*p);//40  
  71. printf("*p+1 %d\n",*p+1);//41  
  72. printf("*p+2 %d\n",*p+2);//42  
  73.   
  74. printf("*p %d\n",*p);//40  
  75. printf("*p+1 %d\n",*(p+1));//82  
  76. printf("*p+2 %d\n",*(p+2));//67  
  77.   
  78. struct card{  
  79. int pips;  
  80. char suit;  
  81. }c1,c2;  
  82. c1.pips=3;  
  83. c1.suit='5';  
  84. c2=c1;  
  85. printf("struct c2.pips: %d\n",c2.pips);  
  86.   
  87. typedef struct{  
  88. int re;  
  89. int im;  
  90. }complex;  
  91. complex as,ac[2];  
  92. as.re=89;  
  93. ac[0].re=1;  
  94. ac[1].re=2;  
  95. printf("struct ac[0].re: %d\n",ac[0].re);  
  96. printf("struct ac[1].re: %d\n",ac[1].re);  
  97. printf("struct ac[0].re: %d\n",ac[0].re);  
  98.   
  99. struct student tmp;  
  100. tmp.last_name="Canada";  
  101. tmp.grade='A';  
  102. tmp.student_id=122;  
  103. tmp.a=0;  
  104. printf("struct tmp.last_name: %s\n",tmp.last_name);  
  105.   
  106. struct employee_data e1;  
  107. e1.a=12;  
  108. int e11=getdata(e1);  
  109. printf("struct e11: %d\n",e11);  
  110.   
  111. int e12=getdata_add(&e1);  
  112. printf("struct e12: %d\n",e12);  
  113.   
  114. //与或非  
  115. int y1=3;  
  116. int y2=0;  
  117. int y3=y1&y2;  
  118. printf("y3 &: %d\n",y3);  
  119. printf("-9 >>31: %d\n",abs(-9));  
  120.   
  121. #undef __FD_SETSIZE  
  122. #define __FD_SETSIZE    1024  
  123. printf("#define: %d\n",__FD_SETSIZE);  
  124.   
  125. return 0;  
  126. }  
  127.   
  128. //一个负数右移31位后会变成 0xffffffff,一个正数右移31位则为 0x00000000  
  129. //0xffffffff ^ a + a = - 1  
  130. //因为 1011 ^ 1111 = 0100 异或1111其实是把a的0和1进行了颠倒。  
  131. int abs(int x)  
  132. {  
  133.     return (x ^ (x >> 31)) - (x >> 31);  
  134. }  
  135.   
  136. int getdata(struct employee_data e)  
  137. {  
  138. return e.a;  
  139. }  
  140. int getdata_add(struct employee_data *e)  
  141. {  
  142. return e->a;  
  143. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值