我是C的初学者,已经开始在c中编写代码.我对变量的范围有疑问.当任何变量写入块内时,其范围在该块内.但是,当使用返回字时,如何在块外部访问变量?
例:
int add(int a, int b)
{
int c;//scope of c is within this block
c=a+b;
return c;
} //it ends here
void main()
{
int answer;
answer=add(2,3);//how we gets value of "c " here
printf("%d",answer);
}
Run Code Online (Sandbox Code Playgroud)