C++ Institute CPP Question Answer
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
void myfunction(int i) { cout << " " << i;
}
struct sequence {
int val,inc;
sequence(int s, int i):val(s),inc(i){}
int operator()(){
int r = val; val += inc;
return r;
}
};
int main() {
vector
fill(v1.begin(), v1.end(), sequence(1,1));
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
C++ Institute CPP Summary
- Vendor: C++ Institute
- Product: CPP
- Update on: Jul 25, 2025
- Questions: 228