在C语言中,如何更改没有指针的局部范围变量?

Sil*_*ash 4 c

ncurses库具有无需任何指针即可更改局部范围变量的函数。例如:

int x, y;
getyx(stdscr, y, x);    //to get the current position of the cursor
Run Code Online (Sandbox Code Playgroud)

这是怎么发生的?

Lig*_*ica 6

getyx 不是函数,而是宏。

(忽略该手册void页上非常令人困惑的返回类型;下面的散文告诉我们真相!)

笔记

所有这些接口都是宏。&变量yx。之前不需要“ ” 。

它没有引入或使用新的作用域,因此可以直接“访问” x并保持y原样。

以此类推,请考虑以下内容如何在不使用的情况下工作&

#define doubleIt(x) x *= 2

int main()
{
   int x = 1;
   doubleIt(x);
}
Run Code Online (Sandbox Code Playgroud)