I can initialize two int variables in the for
initialization like this:
#include <iostream>
using namespace std;
int main() {
for(int i = 0, j=i+1; i<4; i++, j++){
cout << "i: " << i << ", j: " << j << endl;
}
return 0;
}
and it prints:
i: 0, j: 1
i: 1, j: 2
i: 2, j: 3
i: 3, j: 4
How I could initialize two variable of different types, for example int and float, like this?
#include <iostream>
using namespace std;
int main() {
for(int i = 0, float j=i+1; i<4; i++, j++){
cout << "i: " << i << ", j: " << j << endl;
}
return 0;
}
This last code returns me a syntax error
, is there a way to accomplish that?