局部变量在函数中定义,例如main()
函数。
#include <stdio.h>
int main() {
int num1;
printf("/nEnter a number: ");
scanf("%d", &num1);
printf("/nYou entered %d/n ", num1);
return 0;
}
局部范围变量与其原始函数相关联,可以在其他函数中重用变量名称。
#include <stdio.h>
int getSecondNumber(); //function prototype
int main()
{
int num1;
printf("/nEnter a number: ");
scanf("%d", &num1);
printf("/nYou entered %d and %d/n ", num1, getSecondNumber());
}
int getSecondNumber ()
{
int num1;
printf("/nEnter a second number: ");
scanf("%d", &num1);
return num1;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266418.html