c_cpp 代码块的变量范围

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 代码块的变量范围相关的知识,希望对你有一定的参考价值。

	do
	{
		int x = get_int("Please input an integer that is between 1 and 23: ");
	}
	while ((x<1) || (x>23)); // Declare "x" inside the while loop, the scope of "int x" only exist within the while loop brackets. Can't use it outside of the while loop brackets.

  // The correct way of declare "int x" if want to use it later after the while loop:
  
	int x;

	do
	{
		x = get_int("Please input an integer that is between 1 and 23: ");
	}
	while ((x<1) || (x>23));

以上是关于c_cpp 代码块的变量范围的主要内容,如果未能解决你的问题,请参考以下文章