阅读背景:

char * str中的str(%s),*str,str(地址),&str,&str[0]之间的不同关系

来源:互联网 
#include <stdio.h>

int main()
{
	char *str = "hello world";
	printf("str=%s\n",str);//hello world
	printf("str=%s\n",&str[0]);//hello world
	printf("*str=%c\n",*str);//h,将格式符换为%s没结果(‘
#include <stdio.h>

int main()
{
	char *str = "hello world";
	printf("str=%s\n",str);//hello world
	printf("str=%s\n",&str[0]);//hello world
	printf("*str=%c\n",*str);//h,将格式符换为%s没结果(‘\0不可知’

	printf("&str=%p\n",&str);//0012FF44
	printf("str=%p\n",str);//00422FD0
	printf("&str[0]=%p\n",&str[0]);//00422FD0

	//str和&str[0]都表示数组的首地址
	//相当于有个指针str,它存放的是数组的首地址,&str就是取str本身的地址

	return 0;
}


不可知’ printf("&str=%p\n",&str);//0012FF44 printf("str=%p\n",str);//00422FD0 printf("&str[0]=%p\n",&str[0]);//00422FD0 //str和&str[0]都表示数组的首地址 //相当于有个指针str,它存放的是数组的首地址,&str就是取str本身的地址 return 0; }#include <stdio.h> int main() { char *str = "



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: