Anonymous
olli
Saksham why spam?
Anonymous
I am only sharing a useful video of c programming
Anonymous
Someone Help?
https://stackoverflow.com/questions/13408990/how-to-generate-random-float-number-in-c
Tostisto
Guyes i generate random float number from interval but have 6 decimals and i need only 2 a = ((float)(rand() % 20001) / 100) - 100;
Vlad
C
Well, then enjoi your rand hardcode :P
Anonymous
Gulshan
#include <algorithm> #include <algorithm> #include <iostream> #include <vector> int main() { int N, Q; std::cin >> N; int arr[N]; std::vector<int> v(N); for (int i = 0; i < N; i++) { std::cin >> arr[i]; v.push_back(arr[i]); } std::sort(arr[0], arr[N - 1]); std::cin >> Q; int arr2[Q]; std::vector<int>::iterator arr3[Q]; for (int i = 0; i < Q; i++) { std::cin >> arr2[i]; arr3[i].push_back(std::lower_bound(v.begin(), v.end(), arr2[i]) - v.begin()); } for (auto i = arr3.begin(); i != arr3.begin(); i++) { std::cout << *i; } return 0; }
Gulshan
Question
Gulshan
i actually thought to do without vectors... but the question says to use lowerbound
Vlad
Also this line of code shall not compile std::sort(arr[0], arr[N - 1]);
Dima
variable length array
Vlad
vla means ??😅
variable length array
Vlad
In ISO C++ size of an array is static
Gulshan
Also this line of code shall not compile std::sort(arr[0], arr[N - 1]);
lets assume the array given is sorted... so lets comment that out... but I can understand, why the errors are generated on arr3.begin() and others too
Gulshan
i actually used vector<int>::iterator
Vlad
And why did you make a vla out of it?
Gulshan
why tho?
since it has been used in the instruction of using lower_bound
Vlad
std::begin(vec) too mainstream, eh?
Gulshan
std::begin(vec) too mainstream, eh?
i guess begin doesnt take any argument
Gulshan
i am confused 😅
Gulshan
where I have used vla ? i dont even know what it is
Vlad
where I have used vla ? i dont even know what it is
you can't cin >> N; and then use it as a size of a array
Gulshan
you can't cin >> N; and then use it as a size of a array
you only told me to do vector<int> a(3) thing... above... so I tried it in this code
Gulshan
so should I use v.resize(N) instead of vector<int> v(N) ???
Vlad
resize is just extra step
Gulshan
and do . is equal to ->
Vlad
and do . is equal to ->
p->field is same as (*p).field
Gulshan
p->field is same as (*p).field
ohhh... shit.. it was basics... i just forgotten that😅
Vlad
you dereference and access the field at the same time basically
Gulshan
#include <iostream> #include <vector> int main() { using namespace std; int m, num; cin >> m; vector<int> v; for (int i = 0; i < m; i++) { cin >> num; v.push_back(num); } int n, val; cin >> n; for (int i = 0; i < n; i++) { cin >> val; vector<int>::iterator low = lower_bound(v.begin(), v.end(), val); if (v[low - v.begin()] == val) cout << "Yes " << (low - v.begin() + 1) << endl; else cout << "No " << (low - v.begin() + 1) << endl; } return 0; } // https://www.hackerrank.com/challenges/cpp-lower-bound/problem
Gulshan
line no. 18
Vlad
what that (v[low-v.begin() +) is doing ??
I guess low-v.begin() is an index of low basically
Vlad
Why couldn't he just *low
Vlad
We will never know
Nils
void graphics_init() { uint64_t framebuffer_size = (stivale->framebuffer_height * stivale->framebuffer_width) * sizeof(struct pixel32); framebuffer_db = malloc(framebuffer_size); memset(framebuffer_db, 0, framebuffer_size); } Hi, any idea why this faults?
Anonymous
Your framebuffer size is too large perhaps
Nils
Your framebuffer size is too large perhaps
nope, the pointer actually is valid.
Vlad
Or you could have UB somewhere else
Vlad
It doesn't have to segfault instantly
Vlad
It's called undefined behavior for a reason
Foxner
Hi. Do compilers optimize expressions inside loops, whose terms don't change, to just a single evaluation before the loop?
su
it depends
Sharma
hi
Igor🇺🇦
Hi. Do compilers optimize expressions inside loops, whose terms don't change, to just a single evaluation before the loop?
You can read about what optimisations are applied on loops using different optimisation levels here: http://www.cs.columbia.edu/~ecj2122/research/x86_loop_optimizations/x86_loop_optimizations.pdf
gulshan
Hello
Álvaro
Could anybody help me? https://stackoverflow.com/questions/64940135/cant-cross-compile-c-program-using-loquendo-arm-libraries-shared-objects-so thanks! 😁
mk
Ya
Oumi koursiou
Syntaxe error 😂
olli
Nils
I agree.
Thank you
A.k
Any one here who can help with kali linux installation? It is showing mssg of NO DISK DRIVE WAS DETECTED
Vinay
Vinay
can someone resolve the error in my prog
Vinay
pls help
Vinay
someone
Talula
I can't see your code...
Talula
Got it...
Andrew
you miss main function