天天看點

c語言 字元數組存放字元串&&指針存放字元串

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	char a[]="hello";//字元數組 
	strcpy(a,"world");
	//  a="world"; a是數組首位址 是一個常量 不能夠被指派 
	printf("%s\n",a);
	
	char *p="hello2";
//	strcpy(p,"world");  p存放的是字元串常量的位址  字元串常量不可以被修改 不能用strcpy 覆寫*p裡的字元串 
	p="world"; 
	printf("%s\n",p);
	exit(0);
 } 
           

繼續閱讀