面試常考的問題
我自己寫程式test遇到一些問題,找答案中
先附上我的test程式
#include
void main (void)
{
char str[] = "value";
char* pts = str;
printf("%d\n",(sizeof(str)/sizeof(char)));
printf("%p\n",str);
printf("%s\n",str);
printf("%c\n",*str);
printf("%c\n",*(str+1));
// printf("%c\n",*(str++)); 問題發現點: 這邊crash掉,但是+1卻可以過!!!!!! 我目前認為應該是因為
// printf("%c\n",(str++); 沒有定義char array的++運算 就像char array也沒有賦值運算一樣
printf("*pts++=%c\n",*pts++);
printf("*++pts=%c\n",*++pts);
printf("*(pts++)=%c\n",*(pts++));
printf("*(++pts)=%c\n",*(++pts));
}
result:
6
0012FF68
value
v
a
*pts++=v
*++pts=l
*(pts++)=l
*(++pts)=e
全站熱搜
留言列表