Whatsup - לינוקס, תוכנה חופשית וקוד פתוח בעברית

תיכנות בלינוקס - שאלה בסיסית thread cpp

Anonymous - 20/01/2020 - 20:59
נושא ההודעה: שאלה בסיסית thread cpp
קוד:

#include <iostream>
#include <vector>
#include <string>

#include <thread>

using namespace std;



void thread_function(int *i)
{
    *i = 3;
    cout<<"thread function Executing int="<< *i <<endl;
}
 
int main() 
{
    int i=2;
    thread th(thread_function,&i);
   
    th.join();   
   
    cout<<"Exit of Main function"<<2<<std::endl;
    return 0;
}

למה לא שניהם שוום שלוש?

קוד:
thread function Executing int=3
Exit of Main function2
bash-3.2$

Anonymous - 20/01/2020 - 21:07
נושא ההודעה:
אני לא מבין מה זה שונה מ:
קוד:

    int r=2;
    int *pr = &r;
    *pr = 7;
    cout << " r pr"<<r<<*pr<<endl;

שכן מציג
קוד:

 r pr77

Anonymous - 20/01/2020 - 21:09
נושא ההודעה:
אי יצאתי מטומטם השארתי את זה קבוע 2

להיתעלם וךמחוק את הפוסט.... סליחה
כל הזמנים הם GMT + 2 שעות