结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数

一、结构体与指针

#include 
#include 
#include 
#define up_to_down(uuu) (downdemo_t *)(uuu->beg)
#define __plc__
typedef struct updemo_s{
  uint8_t *head;
  uint8_t *beg;
  uint8_t *end;
}updemo_t;
typedef struct downdemo_s{
  uint8_t value;
  uint16_t type;
  uint8_t mmentry[0];
}downdemo_t;
typedef struct mmsg_s{
  uint8_t hh;
  uint8_t hhh;
}mmsg_t;
__plc__ int main(int argc, char* argv[])
{
  updemo_t *uu;
  downdemo_t *dd;
  mmsg_t *mm;
  uu=(updemo_t *)malloc(sizeof(updemo_t));
  uu->beg=malloc(sizeof(downdemo_t));
  dd=up_to_down(uu);
  dd->value=4;
  dd->type=8;
  mm=(mmsg_t *)dd->mmentry;
  mm->hh=10;
  mm->hhh=12;
  printf("dd->value: %d\n",dd->value);
  printf("dd->type: %d\n",dd->type);
  printf("mm->hh: %d\n",mm->hh);
  printf("mm->hhh: %d\n",mm->hhh);
  return 0;  
}

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第1张图片

二、sizeof

#include 
#include 
#include 
int main(int argc, char* argv[])
{
  uint8_t a[1];
  uint8_t b[0];
  uint8_t *c;
  printf("a[1]: %ld a: %\n",sizeof(a));
  printf("b[0]: %ld\n",sizeof(b));
  printf("*c: %ld\n",sizeof(c));
  return 0;
}

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第2张图片

#include
#include
#include
int main(int argc,char* argv[])
{
  uint8_t a[1];
  uint8_t b[0];
  uint8_t *c;
  int *d;
  char e;
  int f;
  char g[]={"1234\0"};
  printf("a[0]: %d sizeof(a): %ld\n",a[0],sizeof(a));
  printf("b[0]: %d sizeof(b): %ld\n",b[0],sizeof(b));
  printf("*c: %d sizeof(c): %ld\n",*c,sizeof(c));
  printf("sizeof(d): %ld\n",sizeof(d));
  printf("sizeof(e): %ld\n",sizeof(e));
  printf("sizeof(f): %ld\n",sizeof(f));
  printf("sizeof(g): %ld\n",sizeof(g));
  return 0;
}

 结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第3张图片

三、static

#include 
void func1(void);
static int count=10;
int main()
{
  while(count--){
    func1();
  }
  return 0;
}
void func1(void)
{
  static int thingy=5;
  thingy++;
  printf("thingy is %d ,count is %d\n",thingy,count);
}

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第4张图片

四、extern

first.c


#include 

int count;
extern void write_extern();

int main()
{
  count=5;
  write_extern();
}

support.c

#include 

extern int count;

void write_extern(void)
{
  printf("count is %d\n",count);
}

五、函数指针数组

#include 
#include 

int a()
{
  printf("\n1\n");
  return 1;
}
int b()
{
  printf("\n2\n");
  return 2;
}
int c()
{
  return 3;
}
int d()
{
  return 4;
}
int (*oper_func[])(void)={a,b,c,d};
int main()
{
  for(int i=0;i<4;i++){
    printf("i:%d  oper_func[i]:%d  *oper_func[i]:%d  oper_func[i]():%d\n",i,oper_func[i],*oper_func[i],oper_func[i]());
  }
}

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第5张图片

六、函数指针

#include 

int (*p1)(int, int);
int max(int x, int y)
{
  return x > y ? x : y;
}

int main()
{
  int (*p2)(int, int)= max;
  p1=max;
  int a,b,c,d;
  printf("请输入三个数:");
  scanf("%d %d %d",&a, &b, &c);
  d=p1(p1(a,b),c);
  printf("p1最大的数d是:%d p1:%d\n",d,p1);
  printf("p2(p2(a,b),c):%d p2:%d\n",p2(p2(a,b),c),p2);
  return 0;
}

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第6张图片

七、回调函数

#include 
#include 

void populate_array(int *array, size_t arraySize, int(*getNextValue)(void))
{
  for(size_t i=0; i

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第7张图片

八、

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第8张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第9张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第10张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第11张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第12张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第13张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第14张图片

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数_第15张图片

你可能感兴趣的:(c语言)