while(N--)解析

while()

# include<stdio.h>
int main()
{
    
    
	int N;
	scanf("%d",&N);
	while(N--)
	{
    
    
		printf("%d ",N);
	}
	return 0;
}

在这里插入图片描述

# include<stdio.h>
int main()
{
    
    
	int N;
	scanf("%d",&N);
	N=N+1;
	while(N--)
	{
    
    
		printf("%d ",N);
	}
	return 0;
}

在这里插入图片描述
由上面的运算结果可以得出while(N- -)先判断N是否为零;如果不为零执行N- -而不是执行“{}”中的内容;所以当我们需要用到N的数据时一定要预先处理;
下面的文章对N做了预处理:
https://blog.csdn.net/qq_45858803/article/details/109730905
如果不需要使用数据N的数据,不需要做预处理;

猜你喜欢

转载自blog.csdn.net/qq_45858803/article/details/109731917