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);

    }

  • 相关阅读:
    手动档和自动档
    关于目标:骑行里程破万的感想
    JavaScript基础学习-iterable
    第一个mybatisplus
    MAVEN安装配置
    List和ArrayList的区别
    mysql安装
    Nginx的命令
    Windows Server 2008/2012/2016允许多个用户同时远程桌面
    soapui模拟桩-4 将模拟桩打包成war包
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429456.html
Copyright © 2011-2022 走看看