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

    函数参数一重指针可以改变形参的值

    gcc -g -o test test.c

    文件:test.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    void swap(char *left, char *right){
    char tmp = *left;
    *left = *right;
    *right = tmp;
    }

    void permutation(char* pStr, char* pBegin)
    {
    char *pCh;
    if(!pStr || !pBegin)
    return;

    // if pBegin points to the end of string,
    // this round of permutation is finished,
    // print the permuted string
    if(*pBegin == '\0')
    {
    printf("%s%s\n",pBegin, pStr);
    }
    // otherwise, permute string
    else
    {
    for(pCh = pBegin; (*pCh) != '\0'; ++pCh)
    {
    //char temp = *pCh;*pCh = *pBegin;*pBegin = temp;
    swap(pBegin,pCh);
    permutation(pStr, pBegin + 1);
    //temp = *pCh;*pCh = *pBegin;*pBegin = temp;
    swap(pBegin,pCh);
    }
    }
    }

    void fun(int ** p){
    int j=3;

    printf("子函数 j的地址 %#X:%d\n",&j,j);
    j=4;
    *p = &j;

    }

    void fun1(int * p){
    int i =4;
    printf("fun1子函数 j的地址 %#X:%d\n",&i,i);
    *p=i;
    }

    void strfun(char *str){
    char tmp;
    //str++;
    char *sub="123";
    str=sub;
    printf("str: %s\n",str);
    }

    int main(int argc,char *argv[])
    {
    //printf("Hello!\n");
    char test[] = "abc";
    permutation(test, test);
    char str1[] = "aaa";
    char str2[] = "bbb";
    printf("str1:%s str2:%s\n",str1,str2);
    swap(str1,str2);
    printf("str1:%s str2:%s\n",str1,str2);

    int *ip=0;
    int iret=1;
    fun(&ip);
    printf("主函数 i的地址 %#X\n",ip);
    printf("ip:%d\n",*ip);

    char *pp="qwe";
    strfun(pp);

    printf("test[]:%s\n",test);

    return 0;

    }

  • 相关阅读:
    docker常用命令
    docker安装注意事项
    DataGridView中实现自动编号
    Flask设置配置文件
    python路径找类并获取静态字段
    JavaScript数据类型
    php学习笔记6
    php学习笔记5
    php学习笔记4
    php学习笔记3
  • 原文地址:https://www.cnblogs.com/shicf/p/2946603.html
Copyright © 2011-2022 走看看