zoukankan      html  css  js  c++  java
  • 指针数组和数组指针实例

    1.#include <stdio.h>

    typedef int(AINT5)[5];
    typedef float(AFLOAT10)[10];
    typedef char(ACHAR9)[9];

    int main()
    {
        AINT5 a1;
        float fArray[10];
        AFLOAT10* pf = &fArray;
        ACHAR9 cArray;
        char(*pc)[9] = &cArray;
        char(*pcw)[4] = cArray;
        
        int i = 0;
        
        printf("%d, %d ", sizeof(AINT5), sizeof(a1));
        
        for(i=0; i<10; i++)
        {
            (*pf)[i] = i;
        }
        
        for(i=0; i<10; i++)
        {
            printf("%f ", fArray[i]);
        }
        
        printf("%0X, %0X, %0X ", &cArray, pc+1, pcw+1);
    }

    2.#include <stdio.h>
    #include <string.h>

    int lookup_keyword(const char* key, const char* table[], const int size)
    {
        int ret = -1;
        
        int i = 0;
        
        for(i=0; i<size; i++)
        {
            if( strcmp(key, table[i]) == 0 )
            {
                ret = i;
                break;
            }
        }
        
        return ret;
    }

    #define DIM(a) (sizeof(a)/sizeof(*a))

    int main()
    {
        const char* keyword[] = {
                "do",
                "for",
                "if",
                "register",
                "return",
                "switch",
                "while",
                "case",
                "static"
        };
        
        printf("%d ", lookup_keyword("return", keyword, DIM(keyword)));
        printf("%d ", lookup_keyword("main", keyword, DIM(keyword)));
    }

    3.#include <stdio.h>

    int main(int argc, char* argv[], char* env[])
    {
        int i = 0;
        
        printf("============== Begin argv ============== ");
        
        for(i=0; i<argc; i++)
        {
            printf("%s ", argv[i]);
        }
        
        printf("============== End argv ============== ");
        
        printf(" ");
        printf(" ");
        printf(" ");
        
        printf("============== Begin env ============== ");
        
        for(i=0; env[i]!=NULL; i++)
        {
            printf("%s ", env[i]);
        }
        
        printf("============== End env ============== ");
    }

  • 相关阅读:
    00027_方法的重载
    Creating a Physical Standby Database 11g
    APUE信号-程序汇总
    随手记Swift基础和Optional Type(问号?和感叹号!)
    双十二即将来袭!阿里内部高并发系统设计手册终开源,你那系统能抗住“秒杀”吗?
    ajax初见
    编程基本功:BUG测试步骤尽可能用文档简化,突出重点
    年轻就该多尝试,教你20小时Get一项新技能
    微信小程序-封装请求基准路径、接口API 和使用
    理解Python闭包,这应该是最好的例子
  • 原文地址:https://www.cnblogs.com/wxb20/p/6150569.html
Copyright © 2011-2022 走看看