zoukankan      html  css  js  c++  java
  • C primer Plus_part6

    第十章  数组和指针

    1.const :保护变量不受改变,特别是在作为入参传入函数

                 对于变量:const 不能修改值

                 对于指针: const 可以修改值,但是不能修改指向对象

        

    #include<stdio.h>
    
    int main()
    {
      int arrays [10] = {0};
      const int *p  = arrays;
      int i =0 ;
      *(p+3) = 4;//error 不能通过编译 const 并不智能
    
      for(;i < 10;i ++)
      {
        printf(" %d 
    ",arrays[i]);
    
    
      }
    }

    #include<stdio.h>
    
    int main()
    {
      int arrays [10] = {0};
      const int *p  = arrays;
      int i =0 ;
     // *(p+3) = 4;//error 不能通过编译 const 并不智能
      *(arrays+3) = 4;
      for(;i < 10;i ++)
      {
        printf(" %d 
    ",*(p+i));
    
      }
    }
    
    
    
     

    关于结构体的大小计算

       

    #include<stdio.h>
    
    typedef struct A_s
    {
       int a[10];
    
    
    }A;
    
     typedef struct data_s
    {
          int a ;
            double dou;
            char b[4];
            //char ch;
            A  d;
           // int e;
            char c;
    }data;
    
    int main()
    {
       data data_1={0};
           printf("%d  %d
    ",sizeof(data) ,sizeof(data_1.d));
    }
    ~  

    多次尝试后对于补位理解补齐一个最大的基本类型大小最大补为8。

    #include<stdio.h>
    
    typedef struct A_s
    {
       int a[10];
    
    
    }A;
    
     typedef struct data_s
    {
          short a ;
           // double dou;
            //char b[4];
            //char ch;
           // A  d;
           // int e;
            char c;
    }data;
    
    int main()
    {
       data data_1={0};
           printf("%d  %d
    ",sizeof(data) ,sizeof(A));
    }

    像这个补齐为4.

  • 相关阅读:
    ORA-01207: file is more recent than control file
    ORA-08189
    oracle 修改表空间存储路径
    oracle 日志文件管理
    Oracle ClusterwarePRCT-1011 : Failed to run "oifcfg".&nb
    linux:文件打包与压缩
    linux:查找搜索文件
    Python:lambda表达式(匿名函数)
    网络协议各层概述
    linux:用户及文件权限管理
  • 原文地址:https://www.cnblogs.com/liuchuanwu/p/7112986.html
Copyright © 2011-2022 走看看