Anonymous
break? 🤔
Doesnt work in my case.. or im just not doing it right.
mov $22, %rax
??
mov $22, %rax
What do you mean
mov $22, %rax
Go and read the linux kernel if you want to see the best C program
Apk
nothing like that exists
mov $22, %rax
Send link
https://github.com/torvalds/linux
mov $22, %rax
https://github.com/torvalds/linux
If you understand even one line let us know
Nisim
hi i can asking q on psudo code?
Nisim
to find and return cyc in graph bfs methoud
Nisim
?
Igor🇺🇦
to find and return cyc in graph bfs methoud
There are plenty of examples on the Internet for that like https://www.geeksforgeeks.org/detect-cycle-in-an-undirected-graph-using-bfs/
Nisim
yes but i need to return the cyc not only i have or not
Simone
Hi guys, simple code for write/read from two different file .c with shm, IPC?
Anonymous
hi please can you tell me how to explain this code because im very bad at explaining something
If u r bad at explaining this piece of code , then it's not written by you , simple..
olli
_Bool can hold either 0 or 1, so your condition is always true. Every non-zero number basically becomes 1. If you want to make sure either 0 or 1 is entered, read it as an integer and assign it to the bool after you validate the input. e.g. #include <stdio.h> int main() { printf("%d ", (_Bool)16); printf("%d ", (_Bool)0.5); printf("%d ", (_Bool)2000); printf("%d ", (_Bool)0.00000001); } this prints 1 1 1 1
Sehab
int main() { int i=0, c=0, num; scanf("%d",&num); while(i<num){ if((num/i) == i) printf("Working"); } } Hi everyone, why this code doesn't execute but when you take the input as float, it works fine. Why is that?
Sehab
What input do you provide in the console?
Any input, like you take 25 as an example
olli
int main() { int i=0, c=0, num; scanf("%d",&num); while(i<num){ if((num/i) == i) printf("Working"); } } Hi everyone, why this code doesn't execute but when you take the input as float, it works fine. Why is that?
Your code does not compile, as there is no n. Otherwise you divide by 0 and the behavior of dividing by zero differs when using float. https://stackoverflow.com/a/4480036/4416573
Sehab
Oh sorry, I type it wrong here, it's i<num not i<n
olli
Can you explain it a little to make it simple!
float have reserved values to store inf or 'NaN`, when using float even 0 can have a sign. This is not the case for int where dividing by 0 causes an hardware exception on many platforms , hence the result is different.
Sehab
Thank you
Tarek
Hi guys
randy
Thank you very much
꧁༒ 9H4WK ☬꧂
Hi guys
𝑰𝒛𝒂𝒛 𝑼𝒅𝒅𝒊𝒏 𝑴𝒂𝒉𝒎𝒖𝒅
can anyone solve a programme about left rotation of an array in C ?
Mar!o
xD
klimi
Patient danya hehe
Anunay
Patient danya hehe
He'll soon change his name to "Solve your own assignments or leave this group" 😂
Anunay
xD
Kanni
hello guys
Kanni
I am trying to use "sort" on vectors but it shows error here's my code......
Kanni
#include <iostream> #include <vector> using namespace std; int main() { vector<double>temps; double temp, sum = 0; while (cin >> temp) temps.push_back(temp); for (int i = 0; i < temps.size(); i++) sum += temps[i]; cout << "Average temperature: " << sum / temps.size() << endl; sort(temps.begin(), temps.end()); cout << "Median temperature: " << temps[temps.size() / 2] << endl; }
klimi
Maybe it would be nice to say what error
Corn
I would agree with Klimi. Show your error
Kanni
sort identifier undefined
Kanni
sort identifier not found
Kanni
Severity Code Description Project File Line Suppression State Error (active) E0020 identifier "sort" is undefined
klimi
I dont know much about CPP but dont you need import for STD::sort? // like <algorithm>?
Corn
No. It compiles fine for me. sort is part of the std namespace
Corn
Your logic doesn't make a lot of sense though. Have you tried compiling with c++17? It works for me on that version
Corn
g++ -std=c++17 main.cpp
Corn
Seems to work fine for me but others sites I am looking at say to #include <algorithm>
Kanni
No. It compiles fine for me. sort is part of the std namespace
i don't know what version of c++ this is, but it is visual studio 2019
H A N
why is my program skipping 1 of the 3 input sections?
H A N
I want to input name,number,address. But when i've input name, input directly to the address and pass the number
klimi
Show your code
H A N
#include <iostream> #include <string> #include <cstdlib> #include <cstdio> #include <conio.h> using namespace std; struct SIMPUL { char NIM[10]; char NAMA[20]; int Nilai; struct SIMPUL *LEFT; struct SIMPUL *RIGHT; }; SIMPUL *head; int isEmpty(){ if(head==NULL) return 1; else return 0; } void tambahdepan(char *nim,char *nama,int *nilai){ SIMPUL *baru; baru = new SIMPUL; baru ->NIM[10] = *nim; baru ->NAMA[20] = *nama; baru ->Nilai = *nilai; baru ->LEFT = NULL; baru ->RIGHT = NULL; if( head == NULL){ head=baru; head->RIGHT = baru; head->LEFT = baru;} else{ baru->RIGHT=head; baru->LEFT = head->LEFT; head->LEFT->RIGHT=baru; head->LEFT=baru; } cout<<"DATA MASUK !"<<endl; } void tambahbelakang(char *nim,char *nama,int *nilai){ SIMPUL *baru,*bantu; baru = new SIMPUL; baru -> NIM[10] = *nim; baru -> NAMA[20] = *nama; baru -> Nilai = *nilai; baru -> LEFT = baru->RIGHT = baru; if(isEmpty() == 1){ head=baru; head->RIGHT=head; head->LEFT=head; } else bantu = head -> LEFT; bantu->RIGHT = baru; baru->LEFT = bantu; baru->LEFT=bantu; cout<<"DATA MASUK !"<<endl; } void hapusdepan(){ SIMPUL *hapus,*bantu; char d,e; int f; if(isEmpty() == 0){ if(head->RIGHT != head){ hapus=head; d = hapus->NIM[10]; e = hapus->NAMA[20]; f = hapus->Nilai; bantu = head->LEFT; head = head->RIGHT; bantu->RIGHT = head; head->LEFT = bantu; delete hapus;} else { d = hapus->NIM[10]; e = hapus->NAMA[20]; f = hapus->Nilai; head = NULL; } } cout<<" DATA TERHAPUS !"<<endl; } void hapusbelakang(){ SIMPUL *hapus,*bantu; char d,e; int f; if (isEmpty()==0){ if(head->RIGHT != head){ bantu = head; while(bantu->RIGHT->RIGHT != head){ bantu = bantu->RIGHT; } hapus = bantu->RIGHT; d = hapus->NIM[10]; e = hapus->NAMA[20]; f = hapus->Nilai; bantu->RIGHT = head; delete hapus; } else { d = hapus->NIM[10]; e = hapus->NAMA[20]; f = hapus->Nilai; head = NULL; } cout<<"DATA TERHAPUS !"<<endl; }} void tampildepan(){ SIMPUL *bantu; bantu = head; if(isEmpty()==0){ do{ cout<<bantu->NIM<<" "<<endl; cout<<bantu->NAMA<<" "<<endl; cout<<bantu->Nilai<<" "<<endl; bantu=bantu->RIGHT; }while(bantu!=head); cout<<endl; } else cout<<"Masih kosong\n"; } void tampilbelakang(){ SIMPUL *bantu; bantu = head; if(isEmpty()==0){ do{ cout<<bantu->NIM<<" "<<endl; cout<<bantu->NAMA<<" "<<endl; cout<<bantu->Nilai<<" "<<endl; bantu=bantu->LEFT; }while(bantu!=head); cout<<endl; } else cout<<"Masih kosong\n"; } int main() { char ulang; int nil; char namasaya; char nim; menu: int pil; cout<<"\n CIRCULAR DOUBLY LINKED LIST\n"<<"======================================\n\n"; cout<<" 1. INSERT KIRI\n"; cout<<" 2. INSERT KANAN\n"; cout<<" 3. HAPUS KIRI\n"; cout<<" 4. HAPUS KANAN\n"; cout<<" 5. CETAK DARI KIRI\n"; cout<<" 6. CETAK DARI KANAN\n"; cout<<" 7. KELUAR\n\n"; cout<<"======================================\n\n"; cout<<"Pilihan ( 1-7 ) = ";cin>>pil; system("cls"); switch(pil){ case 1: cout<<"\nInsert Data dari Kiri\n"<<endl; //printf("\nMasukan Nama Mahasiswa : "); gets(&namasaya); cout<<"\nMasukan Nama Mahasiswa\t : ";gets(&namasaya); cout<<"\nMasukan NIM Mahasiswa \t : ";gets(&nim); cout<<"\nMasukan Nilai Mahasiswa\t : ";cin>>nil; tambahdepan(&nim, &namasaya, &nil); cout<<"Kembali ke menu (Y/N) ? : "; cin>>ulang; if(ulang=='Y'||ulang=='y'){ system("cls"); goto menu; } else exit(1); } cin.get(); return 0; }
H A N
I cant input "Nama Mahasiswa" and straight to "NIM"
ברני
I cant input "Nama Mahasiswa" and straight to "NIM"
Try to send it in online compiler so they could help you better.
我是大娃
why spinlock is slower than pthread_mutex?
Ammar
why spinlock is slower than pthread_mutex?
Quoted from Linus Torvalds' email: What happens is that (a) since you're spinning, you're using CPU time (b) at a random time, the scheduler will schedule you out (c) that random time might ne just after you read the "current time", but before you actually released the spinlock. So now you still hold the lock, but you got scheduled away from the CPU, because you had used up your time slice. The "current time" you read is basically now stale, and has nothing to do with the (future) time when you are actually going to release the lock. Somebody else comes in and wants that "spinlock", and that somebody will now spin for a long while, since nobody is releasing it - it's still held by that other thread entirely that was just scheduled out. At some point, the scheduler says "ok, now you've used your time slice", and schedules the original thread, and now the lock is actually released. Then another thread comes in, gets the lock again, and then it looks at the time and says "oh, a long time passed without the lock being held at all".__ [...] [...] [...] You need to use a realtime scheduler for that (or be the kernel: inside the kernel spinlocks are fine, because the kernel itself can say "hey, I'm doing a spinlock, you can't schedule me right now").
我是大娃
I use multi-core cpu
Ammar
I do not really know how to do that in userspace. But, Linus said you have to be the kernel for doing spinlock.
我是大娃
#include "../util/Timer.hpp" #include <atomic> #include <functional> #include <iostream> #include <thread> #include <mutex> using namespace std; class SpinLock { public: SpinLock () { _flag.store(false); } bool TryLock() { bool expect = false; return _flag.compare_exchange_weak(expect, true); } void Lock() { bool expect = false; while(!_flag.compare_exchange_weak(expect, true)) expect = false; } void UnLock() { _flag.store(false); } private: atomic<bool> _flag; }; SpinLock g_lock; void func(int &arg, int total) { while(total-- > 0) { g_lock.Lock(); ++arg; g_lock.UnLock(); } } mutex g_mutex; void func2(int &arg, int total) { while(total-- > 0) { g_mutex.lock(); ++arg; g_mutex.unlock(); } } const int kAddNum = 1000000; const int kRoundNum = 100; int main() { Timer t; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value = 0; thread a(func, ref(value), kAddNum); //thread b(func, ref(value), kAddNum); a.join(); //b.join(); } t.TimerEnd(); cout << t << endl; t.TimerBeg(); for(int i = 0; i < kRoundNum; i++) { int value2 = 0; thread c(func2, ref(value2), kAddNum); //thread d(func2, ref(value2), kAddNum); c.join(); //d.join(); } t.TimerEnd(); cout << t << endl; return 0; }
我是大娃
here is my code
我是大娃
func2 is faster than func
我是大娃
I don't know why
Ammar
I don't know why
Linus explained it in detail here: https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723 Check it up.
我是大娃
ok, I'll check
Iakovos
Hello guys! I'm trying to return a value to main from a function called within a function but the output I get is 0 https://pastebin.pl/view/8db37ebc The value I'm trying to return is "comparisons" Any help is much appreciated!
Ahmet
/helllo
Anonymous
in a scroll bar, the thumb size is only set when 1. the document width and/or height changes. 2. the window width and/or height changes. or 3. the scroll bar width and/or height changes. right?
Vladislav
Severity Code Description Project File Line Suppression State Error (active) E0020 identifier "sort" is undefined
You may read a litle bit more about the compilation process. You may check which sources are used in your Translation Unit and figure out the problem. The link is vg-blog .tech /archives / 27
mov $22, %rax
Be the kernel
ahahahahahah
Anonymous
Can someone help me analyze a question?