我必须使函数与这些类似(但更复杂)。我们不运行它们,只是确保这些指针接收给定的值。有没有快速简单的方法来测试并确保我们正确地解决这些类型的问题?我的问题是,我可以将什么样的参数传递给这个函数来测试它?
int function(int *n)
{
*n = 3;
}
最佳答案
尝试将地址传递给函数:
int storeThree(int *p) {
*p = 3;
}
// Test function
void test() {
int x = 5; //any integer other than what storeThree is going to fill
storeThree(&x);
assert(x == 3);
}
关于c - 测试 C 中的指针函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624519/