zoukankan      html  css  js  c++  java
  • C字符指针数组的使用

    #include <stdio.h>
    #include <stdlib.h>
    int main(){
    	
    	//字符数组的使用
    	char str[] = {'z','b','c',''};
    	//字符数组
    	printf("str地址:%p str[0]=%c str[0]地址:%p 
    ",str,str[0],&str[0]);
    	printf("str地址:%p str[1]=%c str[1]地址:%p 
    ",str,str[1],&str[1]);
    	printf("str地址:%p 打印串:%s
    ",str,str);
    	//使用指针
    	str[0] = 'w';
    	printf("str地址:%p 打印新串:%s
    ",str,str);
    	printf("*********************************************************
    ");
    	//字符指针数组的使用
    	char *str2[] = {"zhangsan","lisi","wangwu"};
    	printf("字符串数组元素str2[0]:%s 元素str2[0]地址:%p 字符串指针首地址:%p
    ", str2[0],&str2[0],str2);
    	printf("字符串数组元素str2[1]:%s 元素str2[1]地址:%p 字符串指针首地址:%p
    ", str2[1],&str2[1],str2);
    	printf("打印*(str2+1)的元素:%s 打印*str2+1的元素:%s 打印该地址:%p 
    ", *(str2+1), *str2+1, str2+1);//这个是二级指针char** str2本身就是一个指针 指针+1 然后 *;就是取值
    	//也可以定义一个二级指针
    	char **pp = str2;
    	printf("打印pp指向的元素地址:%p *pp=%s  %s
    ", pp, *pp, *(pp+1));//必须是*(pp+1) 不能是*pp+1 否则就是查元素zhangsan的值+1 输出:hangsan
    	
    	printf("*********************************************************
    ");
    	
    	return 0;
    	
    }
    

      

  • 相关阅读:
    luogu P1833 樱花 看成混合背包
    luogu P1077 摆花 基础记数dp
    luogu P1095 守望者的逃离 经典dp
    Even Subset Sum Problem CodeForces
    Maximum White Subtree CodeForces
    Sleeping Schedule CodeForces
    Bombs CodeForces
    病毒侵袭持续中 HDU
    病毒侵袭 HDU
    Educational Codeforces Round 35 (Rated for Div. 2)
  • 原文地址:https://www.cnblogs.com/wanglijun/p/8587967.html
Copyright © 2011-2022 走看看