zoukankan      html  css  js  c++  java
  • c语言指针

    指针与一维数组:

    指针存储的是变量的地址.

    示例程序:

    #include <stdio.h>

     

    void main(){

           int arr[] = {12, 15, 16};

           int *p = arr;

           p++;

           printf("%d", *p);

    }

     

    示例程序:

    #include <stdio.h>

     

    void main(){

           int arr[] = {12, 15, 16};

           int *p = arr;

           *(p+1) = 17;

           p++;

           printf("%d", *p);

    }

     

    动态分配内存:

    示例程序:

    #include <stdio.h>

    #include <stdlib.h>

     

    int main(){

           int *p;

           p = malloc(sizeof(*p));

           if(p == NULL){

                  return -1;

           }

           *p = 100;

           printf("%d", *p);

           free(p);

           return 0;

    }

     

    示例程序:

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

     

    void *fun(char *p, int i){

           p = malloc(i);

           strcpy(p, "hello");

           return p;

    }

     

    int main(){

           char *p = NULL;

           int i=32;

           p = fun(p, i);

           printf("%s", p);

           free(p);

    }

  • 相关阅读:
    AJAX封装(IE)
    CSS3线性渐变
    [Kafka] [All about it]
    [Java][内存模型]
    [python] [Jupyter Notebook]
    [Paper][Link note]
    [TODO]
    [Java] [Singleton] [DCL][happens-before]
    [Java concurrent][Collections]
    Unity AssetBundles and Resources指引 (四) AssetBundle使用模式
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429456.html
Copyright © 2011-2022 走看看