Question: What does the following program output? #include #include using namespace std; void outodd ( ) { for ( int i = 1 , i <

What does the following program output?
#include
#include
using namespace std;
void outodd(){
for (int i =1, i <100; i+=2)
cout << i << endl;
}
void outeven(){
for (int i =2; i <101; i+=2)
cout << i << endl;
}
int main(){
thread t1(outodd);
thread t2(outeven);
t1.join();
t2.join();
}
choose the correct answer
The odd numbers and even numbers are mixed in an unpredictable manner.
The odd and even umbers alternate, because the threads take turns
All the odd numbers 1-99, followed by all the even numbers 2-100(always). Because the odd thread is started first
The program crashes, because the threads conflict with each other

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!