zoukankan      html  css  js  c++  java
  • android109 结构体,联合体,枚举,自定义

    #include <stdio.h>
    #include <stdlib.h>
    
    void study(){
         printf("吃饭睡觉打李志
    ");
    }
    
    //定义一个结构体 ,C语言没有对象, 
    struct student{
           int age;
           int height;
           char sex;//char是1个字节,但是会补齐为4个字节,这是为了方便位移。 
           //结构体中不能定义函数,但可以定义函数指针
           void (*studyP)(); 
    }
    
    main(){
           //定义结构体的变量 
           struct student st = {20, 180, 'm', study};
           printf("%d
    ", st.age);
           printf("结构体的长度%d
    ", sizeof(st));//4+4+4+4 
           
           //调用函数指针有三种写法 
           st.studyP();//调用函数不用函数名,用函数指针。 
           //定义结构体指针 
           struct student* stp = &st;
           (*stp).studyP();
           
           stp->studyP();//变量用点指针用箭头 
           system("pause"); 
    }
    #include <stdio.h>
    
    enum WeekDay
    {
    Monday = 10,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
    };
    
    int main(void)
    {
      //int day;
      enum WeekDay day = Sunday;
      printf("%d
    ",day);//16 
      system("pause");
      return 0;
    }
    #include <stdio.h>
    #include <stdlib.h>
    
    main(){
           //定义一个联合体 
           union{long long i; short s; char c} un;
           un.i = 3;
           printf("%d
    ", un.i);
           printf("联合体的长度%d
    ", sizeof(un));// 8
           system("pause"); 
    }
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef int haha;
    main(){
           haha i = 3;//haha就是int 
           printf("%d
    ", i);
           system("pause"); 
    }
  • 相关阅读:
    hadoop运行mahout问题解决方法
    在cdh5.1.3中在mapreduce使用hbase
    scala-eclipse
    创建cloudera-cdh5本地yum源
    HttpClient 操作总结
    Java NIO 操作总结
    linux 操作总结
    白话机器学习
    Java(jdk1.7) 陷阱
    Weibo Crawler in Action
  • 原文地址:https://www.cnblogs.com/yaowen/p/4985392.html
Copyright © 2011-2022 走看看