In "void pointers" example in the tutorial on cplusplus.com, I try to compare like following. Why do we still need *
in parenthesis? What is happening when no *
?
void increase(void* data, int psize) {
if (psize == sizeof(char)) {
char* pchar;
pchar = (char*) data;
cout << "pchar=" << pchar << endl;
cout << "*pchar=" << *pchar << endl;
//++(*pchar); // increases the value pointed to, as expected
++(pchar); // the value pointed to doesn t change
} else if (psize == sizeof(int)) {
int* pint;
pint = (int*) data;
//++(*pint); // increases the value pointed to, as expected
++(pint); // the value pointed to doesn t change
}
}
int main() {
char a = x ;
int b = 1602;
increase(&a, sizeof(a));
increase(&b, sizeof(b));
cout << a << ", " << b << endl;
return 0;
}
接受解决办法后的最新情况 我试图根据“Cody Gray”的回答,澄清我得到的东西。 <代码>pchar的地址已加起来,以指明非专利地点。 但是,由于<代码>a 载于main
,而不是pchar
, 即<编码>。 仍然印刷了某种意义的价值(例如是x)。