c - 测试 C 中的指针函数

标签 c pointers testing arguments

我必须使函数与这些类似(但更复杂)。我们不运行它们,只是确保这些指针接收给定的值。有没有快速简单的方法来测试并确保我们正确地解决这些类型的问题?我的问题是,我可以将什么样的参数传递给这个函数来测试它?

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/

相关文章:

C - 通用函数 : swap two items in array

angularjs - 在 Protractor 中包含下划线 javascript 库

c - 从文件中逐字符读取并将每一行放入字符串中

c - 获取 PsSetCreateProcessNotifyRoutineEx 形式的 ImageFileName 失败

c - 需要帮助来理解 free() 函数在 C 中的工作原理

c - 搜索数组成员之间差异的函数

c - 隐藏的可打印文本

c - 同时定义和赋值的变量

testing - TestCafe - GetBposShellInfoNavBarData 测试失败

java - 测试NG : run tests sequentially