首页 > 编程语言 > 详细

C语言二级指针和一级指针

时间:2020-10-21 09:35:15      阅读:36      评论:0      收藏:0      [点我收藏+]

指针使用:(1)操作单个地址   修改单个值  (2) 得到某一一串的连续首地址,遍历访问想要地址,然后操作地址,修改某个值            比如二级指针存储多个一级指针的首地址    一级指针存取 多个变量首地址    经常配合使用 ARRAY_SIZE宏  

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

// 如何求一个数组多大
//    sizeof(xxx)
// 如何求一个数组多少个元素
// sizeof(xxx)/sizeof(xxx[0])

typedef struct dev_op
{
    int  (*open_dev)(char*nodename,int flag);
    int (*read_dev)(int fd,void*buf,int size);
    int (*write_dev)(int fd,void*buf,int size);
}ST_DEV_OP_T;


static int  open_dev(char*nodename,int flag)
{
    int ret = 0;


    return ret;
}

static int  read_dev(int fd,void*buf,int size)
{
    int ret = 0;


    return ret;
}


static int  write_dev(int fd,void*buf,int size)
{
    int ret = 0;


    return ret;
}

static  ST_DEV_OP_T* pp_mtda_array[5] = {




};

//0-8 ?
int main()
{

    ST_DEV_OP_T  mtd_ops[] = {
      [0].read_dev = read_dev,
      [1].write_dev = write_dev,
    };
    ST_DEV_OP_T* p_mtd = NULL;
    p_mtd  = (ST_DEV_OP_T*)mtd_ops;
    ST_DEV_OP_T** pp_mtd = &p_mtd;
    pp_mtd[0] = p_mtd;
    pp_mtd[1] = p_mtd;
    pp_mtd[2] = p_mtd;
    pp_mtd[3] = p_mtd;
    pp_mtd[4] = p_mtd;

    pp_mtda_array[0] = pp_mtd[0];
    printf("arrary size is %d\n",ARRAY_SIZE(mtd_ops));
    printf("** size is %d\n",ARRAY_SIZE(pp_mtd));
    printf("** size of %d\n",ARRAY_SIZE(pp_mtda_array));
    //

    for(;;);
    return 0;
}

  

 

C语言二级指针和一级指针

原文:https://www.cnblogs.com/nowroot/p/13850141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!