在下列情況下,我得到NumRecPrinted = 0,即num爲0傳遞指針函數沒有返回值
int main()
{
int demo(int *NumRecPrinted);
int num = 0;
demo(&num);
cout << "NumRecPrinted=" << num; <<<< Prints 0
return 0;
}
int demo (int *NumRecPrinted)
{
int no_of_records = 11;
NumRecPrinted = &no_of_records;
}
您沒有更改int的值,您已經爲指針指定了新的地址。這應該是'* NumRecPrinted = no_of_records;' – 2012-02-09 14:33:15