Fatih
Why?
because my variables are integer
klimi
Mhm, I see it now
klimi
What values have you tried inputting?
klimi
I think you have the scanf format wrong
Fatih
for exampe. When I entere 5. The sum must be 15. But get everytime 0 as result
klimi
I think it should be print the "n =" and then do just %i
klimi
It is probably the scanf, you can take the return value of scanf to see how many items it has scaned
Fatih
I think it should be print the "n =" and then do just %i
Thank you. Now it works scanf("%i",&n);
.
guys is there any exam book Or smt resources
Anonymous
guys is there any exam book Or smt resources
I think u meant "guys" ... or i am in wrong channel...
Anonymous
Dima
lol
Anonymous
Guys could anyone tell me why do we use volatile keyword any practical examples?
Anonymous
I need some help
Kartik
What is the fflush() function
Артем
Guys could anyone tell me why do we use volatile keyword any practical examples?
As far as I know, you need to ise volatile for variables, that can change very fast, or mustn't be optimized. Ex. This code int a, b; uint8_t foo (a, b) { return a + a + b } As soon as vars aren't volatile, 'a' variable may change during sum process. Or it can be optimized out But with volatile things are good
Anonymous
import time driver = webdriver.Chrome() driver.get("https://www.canva.com/q/pro-signup/") time.sleep(6) driver.switch_to.frame(driver.find_element_by_class_name('rbV9vo63iaj7sGd7XwS4h')) elem = driver.find_element_by_name("//iframe[contains(@name, '_hjRemote')]") It cant find element last line. i tried contains, starts with and indexing but none worked.
Anonymous
Suppose I have this: vector<vector<int>> edgeList; I want a vector containing w, (x,y) for multiple values (hence, vector of vectors) I have seen this: edgeList.push_back({w, x, y}); how does this work? Why can't I do that individually, like: edgeList.push_back(w); edgeList.push_back(x); edgeList.push_back(y);
Anonymous
ok i am wrong, it expects vector
Anonymous
is there any other way, like, to store in vector of vectors
Anonymous
Suppose I have this: vector<vector<int>> edgeList; I want a vector containing w, (x,y) for multiple values (hence, vector of vectors) I have seen this: edgeList.push_back({w, x, y}); how does this work? Why can't I do that individually, like: edgeList.push_back(w); edgeList.push_back(x); edgeList.push_back(y);
In the former case you are pushing an initializer_list containing ints which can be implicitly converted to a vector of ints. In the latter case you are pushing an int where a vector<int> is expected and hence the compiler will flag it as an error.
Anonymous
yes right so is that the only way to push values?
You can push anything for which there is a non explicit converting constructor defined in vector class.
klimi
Guys could anyone tell me why do we use volatile keyword any practical examples?
When you are working with threads and you want to use shared variable, you need to mark it as volatile. It means that it can change outside of the current thread, meaning that if you need to work with it, you need to load it again from memory into register, do work with it, and then as fast as possible put it back in memory.
Golden Age Of
yes right so is that the only way to push values?
With c++ 17 you can kinda create tuple and vector of tuples and push there your tuples with data
Golden Age Of
yes right so is that the only way to push values?
Or if you mean METHODS, there is also INSERT method for the vector where you can choose the place to push
Anonymous
When you are working with threads and you want to use shared variable, you need to mark it as volatile. It means that it can change outside of the current thread, meaning that if you need to work with it, you need to load it again from memory into register, do work with it, and then as fast as possible put it back in memory.
No. This is not the right use case for volatile. volatile is pretty much useless as far as multithreading is concerned because the C++ standard doesnt define any acquire release semantics for volatile data. volatile finds its use only in low level system programming where a variable's value can be changed by factors external to your code and hence the compiler must be on its toes to not carry out any optimizations on them. If you are working an multithreading application at a higher level than systems programming or embedded programming, volatile is pretty much useless.
Anonymous
Or if you mean METHODS, there is also INSERT method for the vector where you can choose the place to push
hmm, right thanks guys although i generally use ({x,y}) for make_pair too, ig i'll stick to it
Anonymous
hmm, right thanks guys although i generally use ({x,y}) for make_pair too, ig i'll stick to it
Read about Uniform Initialization introduced in C++11. This would clear most of your doubts.
Anonymous
Read about Uniform Initialization introduced in C++11. This would clear most of your doubts.
There is also a related but different concept called Aggregate Initialization which uses the same syntax but doesnt apply to the use case you presented earlier.
Golden Age Of
hmm, right thanks guys although i generally use ({x,y}) for make_pair too, ig i'll stick to it
Make pair mainly you need for the objects constructors with parameters
Anonymous
With c++ 17 you can kinda create tuple and vector of tuples and push there your tuples with data
Why do you need C++17 for that? tuples were there in C++11 itself.
Golden Age Of
Why do you need C++17 for that? tuples were there in C++11 itself.
In C++ 17 its more comfortable with decomposition
Anonymous
Anonymous
Anonymous
I have this: priority_queue< pair<int, int>, vector <pair<int, int>> , greater<pair<int, int>> > Q; Now let's say, I need vector instead of a pair So will the middle term become vector <vector <int, int>> ?
Anonymous
The first element will also change to vector<int> and the greater template should also change.
yes ofc, the first and the last term will change i was asking about the middle one, since pq in STL has this form of having a vector with it
Anonymous
yes ofc, the first and the last term will change i was asking about the middle one, since pq in STL has this form of having a vector with it
The second template argument is the container which the priority queue will use to manage your objects. If your first element is T, then the second element can be a vector<T> which it is by default or it can be a deque<T> even. The third template argument is the comparison operation to be used. In your case since you are using a min priority queue it would be greater<T>
Apk
printf("hhack"+1); How is this line valid? I thought you can't use + operator between int and string.
Anonymous
printf("hhack"+1); How is this line valid? I thought you can't use + operator between int and string.
"hhack" is a string literal which decays to a pointer which points to the first 'h'. You add 1 to it to make it point to the second 'h'. So printf prints the string starting from there.
Anonymous
Ohh I see. Thanks
same reason why arr[i] and i[arr] both work. decays into pointer arithmetic.
Me
#include <studio.h> int perimeter (int l,int w) int main () { int a=2,b=3, P; P= perimeter (a,b); printf("Perimeter = %d \n",P); return 0; } Int perimeter(int l,int w) { int z; z= 2*(l+w) return z; } What is the problem here?? It does not run. Somebody help please
Me
State the error so easier to help you.
Don't know the actual error because my compiler does not show me the error but it can't run it
Me
State the error so easier to help you.
Can I send a photo of program or?
Anonymous
Can I send a photo of program or?
No pls. What do u mean your compiler doesnt show u the error and doesnt run? Does it run a simple helloworld?
Anonymous
Don't know the actual error because my compiler does not show me the error but it can't run it
get a better compiler. there are four issues in the code, a good compiler shows 2 out of the 4 together with example code that will fix the issue. the other 2 are shown as errors but it should be obvious how to fix by reading the error message.
Cris
https://godbolt.org/z/dobbYchhW I just pasted your code here, there are some errors, but they should be easy to spot now
for example, #include <studio.h> never heard of a stUdio.h did you mean stdio.h (which stands for standard i/o) ?
Cris
godbolt just works. make your fixes there, then we can talk about configuring stuff because they are two different matters
Anonymous
for (auto &[a, b]: freq) freq is a hashmap but what does the [a,b] mean?
Anonymous
Looks like a range
Anonymous
for (auto &[a, b]: freq) freq is a hashmap but what does the [a,b] mean?
when you dereference an iterator to a standard map you get a pair. [a, b] assigns the first element of the pair to a and the second element to b
Apk
Why would you do that?
Eric
can anyone help with this please,Write a main program with local objects y and z of type first and second respectively and make reference calls to the defined functions insert , swap, view to test the program.
klimi
Google mostly
Code WHIZ
What is the fflush() function
As name suggest it is used to clear the buffer i.e to extra input . For eg if we have to 2 enter two integer and we enter 3 then last one will be in buffer and buffered will considered as input in next input which is not intended.
Anonymous
https://gist.github.com/52cbe6991c05c5814ed67970583230cb is this a correct array implementation?
@𝑺𝒐𝒃𝒌𝒂
Hi! if(division by zero) cerr<<"ERROR: division by zero." ; I know cerr is used for error messages. But is there some advantage of using cerr instead of cout? - - > like: if(division by zero) cout<<"ERROR: division by zero." ;
Anonymous
https://gist.github.com/52cbe6991c05c5814ed67970583230cb is this a correct array implementation?
I recommend you reference the interface of std::vector or container requirement.
Anonymous
https://gist.github.com/52cbe6991c05c5814ed67970583230cb is this a correct array implementation?
I am not sure what you intend to use this array for. If it is meant to be a general purpose implementation then it is not good. First of all it is not exception safe. Second, it wouldnt work for anything but built in types and POD types. You can't store stuff like strings in your array implementation seeing that you are using memcpy and stuff. Third, it doesnt handle uniform initialization. Fourth, it doesnt allow indexing into const arrays. Fifth, it doesnt support iterators nor iteration. Sixth, the interface is not good.