Tag: 一生

安全地将指向自动变量的指针传递给函数?

假设我有一个函数声明并初始化两个局部变量 – 默认情况下,存储持续时间为auto 。 然后,该函数调用第二个函数,它传递这两个局部变量的地址。 第二个function可以安全地使用这些指针吗? 一个简单的程序化示例,以补充该描述: #include int adder(int *a, int *b) { return *a + *b; } int main() { auto int a = 5; // `auto’ is redundant; included for clarity auto int b = 3; // adder() gets the addresses of two auto variables! is this an issue? int result = […]