标题: 数组和指针并不相同 [打印本页]

作者: daniu    时间: 2014-12-25 16:12
标题: 数组和指针并不相同


作者: daniu    时间: 2014-12-25 16:12


#include<stdio.h>

void main()
{
char *ptr="123456";
char str[]="abcdef";

ptr[2]='c';//注:可以通过编译
str[2]='3';

printf("%c\n",str[2]);// ?
printf("%s\n",str);// ?
printf("%c\n",ptr[2]);// ?
printf("%s\n",ptr);// ?
}





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1