私は以下のようにconst void*
といくつかのコードを持っている:const void *がCでまだ更新されているのはなぜですか?
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
const int p = 10;
char s[] ="I am newbie";
const void *vp;
vp = &p;
*(int*)vp = 11;
printf("%i\n", *(int*)vp);
vp= s;
printf("%s\n", (char*)vp);
return 0;
}
const void* vp
がまだ更新され、なぜ私の質問はありますか? 私の理解として、const変数は直接更新することはできませんが、それはすべての型に対して正しいのでしょうか?
中間のvoidポインタを使うと、 '*(int *)&p = 11;と比較しても全く違いはありません。 –