是否可以在for循环中声明不同类型的两个变量? [英] Is it possible to declare two variables of different types in a for loop?
本文介绍了是否可以在for循环中声明不同类型的两个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在C ++的for循环的初始化体中声明两个不同类型的变量?
Is it possible to declare two variables of different types in the initialization body of a for loop in C++?
例如:
for(int i=0,j=0 ...
定义两个整数我可以在初始化体中定义一个 int
和 char
defines two integers. Can I define an int
and a char
in the initialization body? How would this be done?
推荐答案
不可能,但您可以这样做:
Not possible, but you can do:
float f;
int i;
for (i = 0,f = 0.0; i < 5; i++)
{
//...
}
f
和 i
使用其他括号:
{
float f;
int i;
for (i = 0,f = 0.0; i < 5; i++)
{
//...
}
}
这篇关于是否可以在for循环中声明不同类型的两个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文