zoukankan      html  css  js  c++  java
  • OC typedef(起别名)

    // #define Integer int
    // 给基本数据类型起别名
    void test() {
        typedef int Integer;
        
        typedef Integer MyInteger;
        
        typedef unsigned int UInteger;
        
        int a = 10;
        
        Integer b = 9;
        
        UInteger c = 11;
        
        MyInteger d = 89;
    }
    
    // 给指针类型起别名
    void test1() {
        char *s = "itcast";
        
        typedef char * String;
        
        String s1 = "itcast";
    }
    
    void test2() {
    //    struct MyPoint {
    //        float x;
    //        float y;
    //    };
    //    struct MyPoint p = {10, 10};
        
        
        typedef struct {
            float x;
            float y;
        } Point;
        
        Point p = {10, 10};
    }
    
    void test3() {
        typedef struct {
            float x;
            float y;
        } Point;
        
        typedef Point * PP;
        
    //    typedef struct Point {
    //        float x;
    //        float y;
    //    } * PP;
        
        Point point = {10.0f, 20.0f};
        
        PP pp = &point;
        
        printf("x=%f, y=%f
    ", pp->x, pp->y);
    }
    
    void test4() {
        typedef enum {
            spring,
            summer,
            autumn,
            winter
        } Season;
        
        Season s = spring;
    }
    
    int sum(int a, int b) {
        int c = a + b;
        printf("%d+%d=%d
    ", a, b, c);
        return c;
    }
    
    // 给指向函数的指针定义一个别名SumPoint
    void test5() {
        typedef int (*SumPoint)(int, int);
        
        SumPoint p = sum;
        
        (*p)(4, 5);
    }
    
    void test6() {
        typedef char * String1;
        #define String2 char *
        
        String1 s1,s2;
    //    String1 s1;
    //    String1 s2;
        
        String2 s3,s4;
    //    char *s3, s4;
    //    char *s3;
    //    char s4;
    }
    
    int main(int argc, const char * argv[])
    {
        
        int a, b;
        
    //    int a;
    //    int b;
        
        return 0;
    }
  • 相关阅读:
    C/C++
    不使用判断语句求一组数中的奇数/偶数个数
    heap(堆)
    One-Hot Encoding(独热编码)
    泰坦尼克号生存预测
    LaTeX 使用笔记
    python学习 —— seaborn、matplotlib、pandas、numpy package的混合使用
    Python 读取本地*.txt文件 替换 内容 并保存
    MySQL基本命令脚本
    MySQL简介
  • 原文地址:https://www.cnblogs.com/liuwj/p/6899746.html
Copyright © 2011-2022 走看看