Coder Social home page Coder Social logo

nepointerarray's Introduction

NePointerArray 指针数组,数组指针

注意:
优先级:() > [] > *

1. 指针

//指针
void pointer() {
    int arr[] = {100, 200, 300};
    for (int i = 0; i < 3; i++) {
        printf("数组 %d\n", arr[i]);
    }
//    int* p = arr;
    int* p = &arr[0];
    *(p + 1) = 400;
    for (int i = 0; i < 3; i++) {
        printf("数组: %d\n", arr[i]);
    }
}

2. 指针数组

是一个数组,里面存放多个指针

//int* p[n]
void pointerArray() {
    int arr[] = {100, 200, 300};
    int* p[3]; //指针数组
    printf("-------操作后-------\n");
    for (int i = 0; i < 3; i++) {
        p[i] = &arr[i];
    }
    
    for (int i = 0; i < 3; i++) {
        printf("数组: %d\n", *p[i]);
    }
}

3. 数组指针

指向一个一维数组的指针,若该一维数组长度为n,则指针+1时会跨越n个数据长度

//int (*p)[n]
void arrayPointer() {
    int arr[3][4] = {
        {100, 200, 300, 400},
        {500, 600, 700, 800},
        {900, 1000, 1100, 1200}
    };
    int (*p)[4];
    p = arr;
    p++;
    for (int i = 0; i < 3; i++) {
        printf("数组: %d\n", (*p)[i]);
    }
}

image

nepointerarray's People

Contributors

tianyalu avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.