您的位置:首页 > 运维架构 > Linux

苏嵌嵌入式linux实训 第 5天

2020-07-14 06:33 134 查看

本人进度计划以及任务                                      

 

 

 

 

复习c语言

本日任务完成情况

(详细说明本日任务是否按 计划完成,开发的代码量)

 

 

今天学习了

1.预处理(宏,条件编译)

2.编码规范

3.指针

  • 指针是什么? 

指针是一个变量(指针变量),保存的是地址

  • 指针类型是根据储存的地址的类型(类型+步长)
  • * &运算符:*取值运算符  &取地址
  • 多维指针的作用:保存前一维的指针变量的地址
  • 指针赋值<一定是相同指针类型赋值>
  • 万能指针:void*:可以接受任何类型指针的值!(不能做取值和自加)
  • 野指针

 4. 数组(内存管理)

  • 数组的定义及初始化
  • 数组名的作用!一维数组,二维数组,三维数组
  • 数组指针
  • 指针数组
  • main参数;命令行参数

 

本日开发中出现的问题汇总

 

 

 

 

练习题:将整数转化为二进制。

  1 #include<stdio.h>
  2 #include<stdlib.h>
  3 int main()
  4 {
  5     int num,a[20],i=0;
  6         printf("Input a number: \n");
  7         scanf("%d",&num);
  8         while(num < 0)
  9                   {
 10                   exit(0);
 11                   }
 12         while(num != 0)
 13                 {
 14                    a[i] = num % 2;
 15                    num = num / 2;
 16                    i++;
 17                 }
 18             i--;
 19         while(i >= 0)
 20                 {
 21                         printf("%d",a[i]);
 22                         i--;
 23                 }
 24         printf("\n");
 25         return 0;
 26 }
 

作业:三维数组输出

  1 #include<stdio.h>
  2 
  3 void print1(char *ptr)
  4 {

  5         printf("ptr = %s\n",ptr);
  6 }
  7 
  8 void print2(char(*ktr)[100])
  9 {
 10         for(int i =0;i<2;i++)
 11         {
 12            printf("ktr[%d]=%s\n",i,*(ktr+i));
 13         }
 14 }
 15 
 16 void print3(char(*str)[2][100])
 17 {
 18         for(int i=0;i<2;i++)
 19         {
 20                 for(int j=0;j<2;j++)
 21                 {
 22                         printf("str[%d][%d}=%s\n",i,j,*(*(str+i)+j));
 23                 }
 24         }
 25 }
 26 
 27 void print4(char **ytr)
 28 {
 29     int i;
 30     for(i = 0; i < 3; i++)
 31     {
 32         printf("ktr[%d] = %s\n", i, *(ytr + i));
 33     }
 34 }
 35 
 36 int main()
 37 {
 38         char ptr[100]="hello";
 39         char ktr[2][100]={"hello1","hello2"};
 40         char str[2][2][100]={{"hello.3","hello.4"},{"hello.5","hello.6"}};
 41         char *ytr[3] = {"hello1", "hello2", "hello3"};
 42         print1(ptr);
 43         print2(ktr);
 44         print3(str);
 45         print4(ytr);
 46 
 47         return 0;
 48 }
 

结果

 

本日未解决问题

 

 

 

 

二进制转化未做到确定位数

其它

 

 

 

 

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: