博客
关于我
C语言指针比较高级的用法及指针数组面试题详解
阅读量:167 次
发布时间:2019-02-27

本文共 2570 字,大约阅读时间需要 8 分钟。

C/C++ ??????

??????

????? C/C++ ????????????

  • ??????

    char c = 'a';
    char* pc = &c;
    *pc = 'a';

    ??????? pc ?????? c ?????? pc ??????????????? pc ??? c ??????

  • ?????

    char* str = "hello world";
    printf("%s\n", str);

    ??????????????????????????????????? str ????????????????? str ???????????????????????????? '\0'?


  • ??????

    ???????????????????????????????????????

  • ??????

    char (*p)[10];
    ??? p ???????? 10 ??????????

  • ?????????????

    int a[10];

    • a ??????????
    • &a ???????

    ?? a + 1 ?? 1 ??????4 ????? &a + 1 ?? 10 ????????????


  • ??????

    ?????????????????????????????????????

  • ??????

    char* arr[4];

  • ??????

    char** arr[5];


  • ???????????

    ??????

  • ???????

    void test(int arr[]);
    void test(int* arr);

    • arr[] ?????????????
    • arr* ??????????????
  • ??????

    • ??????????????
    • void test(int arr[3][5]);
    • void test(int arr[][5]);
  • ????

    void test(int* arr);
    void test(int** arr);


  • ??????

    ?????????????????

  • ??????

    void (*pfun)();

  • ???????

    void PopSort(int* nums, int numsSize, int (*p)(int x, int y)) {    // ...}void GreaterPopSort(int x, int y) { return x > y ? 1 : 0; }void LessPopSort(int x, int y) { return x < y ? 1 : 0; }int main() {    // ?? PopSort ????????? GreaterPopSort ? LessPopSort ???????}

  • ??????

    ????????????????????????

    void test(int* arr, void (*pfun)(int x, int y)) {    pfun(arr[0], arr[1]);}

    ???????? pfun?????????????????


    ????????????????

  • ??????

    int (*prt[10]);
    ??? prt ????? 10 ?????????

  • ???????????

    void (***cpp)(int x, int y);
    ??? cpp ?????????????????


  • ????????

    ?? 1

    int main() {    int a[5] = {1, 2, 3, 4, 5};    int* ptr = (int*)(a + 1); // ????????    printf("%d,%d", *ptr - 1, *ptr);    return 0;}

    ?????4,5


    ?? 2

    int main() {    char a[4] = {'1', '2', '3', '4'};    char* p = a;    printf("%c,%c", *p, *(p + 1));    return 0;}

    ?????1,2


    ?? 3

    int main() {    char a[3] = {'w', 'o', 'r'};    char** pa = a;    printf("%s", *pa);    return 0;}

    ?????wor


    ?? 4

    int main() {    char a[3][2] = {        {'w', 'o'},        {'r', 'k'},        {'a', ' '}    };    char* p = a;    printf("%s\n", p[0]);    return 0;}

    ?????wo


    ?? 5

    int main() {    char a[5][5];    char** p = a;    printf("%p,%d\n", p[4][2], p[4][2] - 'a');    return 0;}

    ?????0x1c4d0, 4


    ?? 6

    int main() {    char a[2][5] = {        {'w', 'o', 'r', 'k', ' '},        {'a', 'l', 'i', 'b', 'a'}    };    char** p = a;    printf("%s\n", p[1][4]);    return 0;}

    ?????a


    ?? 7

    int main() {    char a[] = {"work", "at", "alibaba"};    char** pa = a;    printf("%s\n", pa[1]);    return 0;}

    ?????at


    ?? 8

    int main() {    char a[5] = {'E', 'N', 'T', 'E', 'R'};    char** cpp = a;    printf("%s\n", **cpp);    printf("%s\n", *cpp);    return 0;}

    ?????

    ENTER
    E

    转载地址:http://nzub.baihongyu.com/

    你可能感兴趣的文章
    python 多线程与GIL
    查看>>
    python 多进程-基础
    查看>>
    python 多进程-进阶-进程池
    查看>>
    python 多进程-进阶-进程间通信之Pipe
    查看>>
    python 多进程-进阶-进程间通信之Queue
    查看>>
    python 如何“否定“value : 如果为真则返回假,如果为假则返回真
    查看>>
    Python 如何在 Web 环境中使用 Matplotlib 进行数据可视化
    查看>>
    python 字符串中特定字符替换,截取
    查看>>
    Python 字符串总结
    查看>>
    python 字符串显示中文_Python字符串开头的b"、u"、r"与中文乱码
    查看>>
    Python 字符串的几种拼装方式
    查看>>
    python 存入数据库bigint_python基础_MySQL的bigint类型
    查看>>
    python 学习 面向对象编程
    查看>>
    Python 学习日记第三篇 -- 字典
    查看>>
    Python 学习笔记(一)Data type
    查看>>
    python 安装echarts
    查看>>
    python 安装opencv及问题解决
    查看>>
    Python 安装程序:“写入文件 C:\Python27\pythonw.exe 时出错“
    查看>>
    Python 安装避坑指南:从入门到进阶
    查看>>
    Python 安装配置详解
    查看>>