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

    }

  • 相关阅读:
    Python自动化运维答疑解惑
    MySQL基础
    Centos下常用MySQL语法
    PDO
    生成静态页面的好处
    页面纯静态
    源码安装LNMP
    Nginx URL重写(rewrite)
    防盗链
    自定义菜单
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429456.html
Copyright © 2011-2022 走看看