#include<stdio.h>
main()
{
char c = 'R';
printf("%c\n",c);
c++;
printf("%c\n",c);
char *ptr ="Ramco Systems";
printf("%c\n",(*ptr));
(*ptr)++;
printf("%d\n",(*ptr));
}
第一,第二,第三printf的輸出爲'R','S'&'R'(如預期的那樣)。然而行「(* ptr)++;」給運行時錯誤。有人能解釋爲什麼嗎?增加指針時的模糊行爲
它看起來不像是在遞增指針。您取消引用指針並遞增值。 –
我想你想要的是* ptr ++ :) – useratuniv
我認爲目標是將'R'增加到下一個ansi字符,所以代碼中沒有錯字 - 只是指針指向的內存是不可修改的。 – jwaliszko