C语⾔学习代码⼀.
1. /*------------------------------------------------------------------
2. * ------------------------- scanf 练习 ---------------------------
3. *----------------------------------------------------------------- */
4. /*
5. #include<stdio.h>
6. int main()
7. {
8. int a;
9. printf("请输⼊⼀个整数");
10. scanf("%d",&a);
11. printf("%d\n",a);基础c语言代码
12. return 0;
13. }*/
14. /*&
15. # include<stdio.h>
16. int main()
17. {
18. int a,b;
19. printf("请输⼊⼀个加法格式为:1 + 2:");
20. scanf("%d + %d",&a,&b);
21. printf("%d + %d = %d\n",a,b,a+b);
22. }
23. */
24. /*-----------------------------------------------------
25. *------------------ sizeof 练习----------------------
26. *--------------------------------------------------- */
27. /*#include<stdio.h>
28. int main()
29. {
30. char zi_fu = 0;
31. unsigned char u_zi_fu = 0;
32. printf("变量zi_fu占%d个字节\n",sizeof(zi_fu));
33. printf("char类型变量占%d个字节\n",sizeof(char));
34.
35. printf("变量zi_fu占%d个字节\n",sizeof(u_zi_fu));
36. printf("unsigned char类型变量占%d个字节\n",sizeof(unsigned char));
37. zi_fu='a';
38. sizeof(zi_fu='b');
39. printf("%c\n",zifu);
40. return 0;
41. }*/
42. /*=======================================================
43. * 进制练习
44. *======================================================
45. * */
46. /*#include<stdio.h>
47. int main()
48. {
49. printf("%d %d %d\n",12,012,0x12);
50. printf("%d 0%o 0x%x\n",18,18,18);
51. printf("%p\n",18);
52.
53. return 0;
54. }*/
55. /*============================================================
56. * ⼆进制练习
57. *========================================================= */
58. /*#include<stdio.h>
59. int main()
60. {
61. int shu_zi = 300;
62. unsigned char zi_fr =shu_zi;
63.
64. }
65. */
66. /*=============================================================
67. * 操作符练习
68. *========================================================== */
69. #include<stdio.h>
70. int main()
71. {
72. int shu_zi=0,shu_zi1=0;
73. printf("15/7=%d\n",15/7);//整数类型的运算只保留整数部分。
74. printf("15 %% 7=%d\n",15%7);
75. shu_zi = shu_zi1=7;//取决于运算顺序,如果从左往右则变量值会不同,但实际计算机是以右往左赋值。
76. printf("%d %d\n",shu_zi,shu_zi1);
77. shu_zi +=2;//相当于shu_zi = shu_zi = 2
78. printf("shu_zi是%d\n",shu_zi);
79. shu_zi *= 2+3;//先计算加法在计算⾃乘,因为乘法和赋值⼀起使⽤时,会把优先级降到和赋值⼀样。
80. printf("shu_zi是%d\n",shu_zi);
81. return 0;
82. }
/*------------------------------------------------------------------
* ------------------------- scanf 练习 ---------------------------
*----------------------------------------------------------------- */
/*
#include<stdio.h>
int main()
{
int a;
printf("请输⼊⼀个整数");
scanf("%d",&a);
printf("%d\n",a);
return 0;
}*/
/*&
# include<stdio.h>
int main()
{
int a,b;
printf("请输⼊⼀个加法格式为:1 + 2:");
scanf("%d + %d",&a,&b);
printf("%d + %d = %d\n",a,b,a+b);
}
*/
/*-----------------------------------------------------
*------------------ sizeof 练习----------------------
*--------------------------------------------------- */
/*#include<stdio.h>
int main()
{
char zi_fu = 0;
unsigned char u_zi_fu = 0;
printf("变量zi_fu占%d个字节\n",sizeof(zi_fu));
printf("char类型变量占%d个字节\n",sizeof(char));
printf("变量zi_fu占%d个字节\n",sizeof(u_zi_fu));
printf("unsigned char类型变量占%d个字节\n",sizeof(unsigned char));
zi_fu='a';
sizeof(zi_fu='b');
printf("%c\n",zifu);
return 0;
}*/
/*=======================================================
* 进制练习
*======================================================
* */
/*#include<stdio.h>
int main()
{
printf("%d %d %d\n",12,012,0x12);
printf("%d 0%o 0x%x\n",18,18,18);
printf("%p\n",18);
return 0;
}*/
/*============================================================
* ⼆进制练习
*========================================================= */
/*#include<stdio.h>
int main()
{
int shu_zi = 300;
unsigned char zi_fr =shu_zi;
}
*/
/*=============================================================
* 操作符练习
*========================================================== */
#include<stdio.h>
int main()
{
int shu_zi=0,shu_zi1=0;
printf("15/7=%d\n",15/7);//整数类型的运算只保留整数部分。
printf("15 %% 7=%d\n",15%7);
shu_zi = shu_zi1=7;//取决于运算顺序,如果从左往右则变量值会不同,但实际计算机是以右往左赋值。 printf("%d %d\n",shu_zi,shu_zi1);
shu_zi +=2;//相当于shu_zi = shu_zi = 2
printf("shu_zi是%d\n",shu_zi);
shu_zi *= 2+3;//先计算加法在计算⾃乘,因为乘法和赋值⼀起使⽤时,会把优先级降到和赋值⼀样。
printf("shu_zi是%d\n",shu_zi);
return 0;
}
[cpp]
1. /*------------------------------------------------------------------
2. * ------------------------- scanf 练习 ---------------------------
3. *----------------------------------------------------------------- */
4. /*
5. #include<stdio.h>
6. int main()
7. {
8. int a;
9. printf("请输⼊⼀个整数");
10. scanf("%d",&a);
11. printf("%d\n",a);
12. return 0;
13. }*/
14. /*&
15. # include<stdio.h>
16. int main()
17. {
18. int a,b;
19. printf("请输⼊⼀个加法格式为:1 + 2:");
20. scanf("%d + %d",&a,&b);
21. printf("%d + %d = %d\n",a,b,a+b);
22. }
23. */
24. /*-----------------------------------------------------
25. *------------------ sizeof 练习----------------------
26. *--------------------------------------------------- */
27. /*#include<stdio.h>
28. int main()
29. {
30. char zi_fu = 0;
31. unsigned char u_zi_fu = 0;
32. printf("变量zi_fu占%d个字节\n",sizeof(zi_fu));
33. printf("char类型变量占%d个字节\n",sizeof(char));
34.
35. printf("变量zi_fu占%d个字节\n",sizeof(u_zi_fu));
36. printf("unsigned char类型变量占%d个字节\n",sizeof(unsigned char));
37. zi_fu='a';
38. sizeof(zi_fu='b');
39. printf("%c\n",zifu);
40. return 0;
41. }*/
42. /*=======================================================
43. * 进制练习
44. *======================================================
45. * */
46. /*#include<stdio.h>
47. int main()
48. {
49. printf("%d %d %d\n",12,012,0x12);
50. printf("%d 0%o 0x%x\n",18,18,18);
51. printf("%p\n",18);
52.
53. return 0;
54. }*/
55. /*============================================================
56. * ⼆进制练习
57. *========================================================= */
58. /*#include<stdio.h>
59. int main()
60. {
61. int shu_zi = 300;
62. unsigned char zi_fr =shu_zi;
63.
64. }
65. */
66. /*=============================================================
67. * 操作符练习
68. *========================================================== */
69. #include<stdio.h>
70. int main()
71. {
72. int shu_zi=0,shu_zi1=0;
73. printf("15/7=%d\n",15/7);//整数类型的运算只保留整数部分。
74. printf("15 %% 7=%d\n",15%7);
75. shu_zi = shu_zi1=7;//取决于运算顺序,如果从左往右则变量值会不同,但实际计算机是以右往左赋值。
76. printf("%d %d\n",shu_zi,shu_zi1);
77. shu_zi +=2;//相当于shu_zi = shu_zi = 2
78. printf("shu_zi是%d\n",shu_zi);
79. shu_zi *= 2+3;//先计算加法在计算⾃乘,因为乘法和赋值⼀起使⽤时,会把优先级降到和赋值⼀样。
80. printf("shu_zi是%d\n",shu_zi);
81. return 0;
82. }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论