CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Ketan Lalcheta
#include <iostream>
#include <thread>
using namespace std;
string s1 = "normal variable s1";
thread_local string s2 = "thread_local variable s2";
void changer(){
s1 = "s1 changed";
s2 = "s2 changed";
cout << "\n inside the function:\n";
cout << "&s1 : " << &s1 << " : " << s1 << '\n'
// in threads, s2 is a copy. it's address is different
<< "&s2 : " << &s2 << " : " << s2
<< "\n\n";
}
int main() {
cout << " outside the function:\n";
cout << "&s1 : " << &s1 << " : " << s1 << '\n';
cout << "&s2 : " << &s2 << " : " << s2 << '\n';
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run