int add(int count, ...)
{
// 指针大小与程序位数有关(32位指针是4个字节,64位指针是8个字节)
int intSize = sizeof(int*) / sizeof(int);
int sum = 0;
// cout << &count << endl;
int *p = &count + intSize;
// cout << p << endl;
for (int i = 0; i < count; ++i)
{
sum += *p;
cout << *p << endl;
p += intSize;
}
return sum;
}
int main()
{
cout << add(3, 1, 2, 3) << endl;
return 0;
}
输出:
1
2
3
6