Anonymous
How is "c in depth" book
never got my hands on it
Anonymous
but the reviews say its awesome
Vikas
Can we exit from a recursive function in the middle?
Vikas
How?
Anonymous
How?
Return in the middle
Vikas
But return will just return from current call
Vikas
I want to return back to initial call
Anonymous
Anonymous
You will get to the initial call eventually
Talula
But return will just return from current call
Yes and you return from there too, till everything ends...
Vikas
Ok
Talula
I want to return back to initial call
See for me an old style programmer, I would create a global variable and if that is true, just return, so all the functions would return and end everything.
Vikas
Got it.
Anonymous
C++
Throw an exception and handle it at the point of call
DEV 7
#include <iostream> using namespace std; #define SQUARE(x) x*x int main(){ int x = 36 / SQUARE(6); cout << x; return 0; } can anyone explain this program ? why the output is 36 instead of 1
Anonymous
when you have * /
Anonymous
how
36 / 6 == 6 6 * 6 == 36 You need to do: int x = 36 / (SQUARE(6));
Anonymous
ok
for example here https://discuss.codechef.com/t/operator-precedence-table/14545 you can see when you have * / it will be computed from left to right
Vikas
class Solution { public: //Function to find if the given edge is a bridge in graph. int isBridge(int V, vector<int> adj[], int c, int d) { } }; Should I create dfs function below public: or above it?
artemetra 🇺🇦
class Solution { public: //Function to find if the given edge is a bridge in graph. int isBridge(int V, vector<int> adj[], int c, int d) { } }; Should I create dfs function below public: or above it?
if you want that function to be public then below, if not - put it above the public keyword, it would automatically be set to private 🤔
Vikas
if you want that function to be public then below, if not - put it above the public keyword, it would automatically be set to private 🤔
I am not taking about isBridge function. I wanna know that if I will create new function called dfs, where should I create that.
artemetra 🇺🇦
I am not taking about isBridge function. I wanna know that if I will create new function called dfs, where should I create that.
oh, well my reply still holds if you want dfs to be a publicly accessable function - use it under public, otherwise put it above
Vikas
Ok, thanks
Anonymous
I am not taking about isBridge function. I wanna know that if I will create new function called dfs, where should I create that.
Your isBridge function actually determines if it is a one-way bridge between two strongly connected components of the graph I believe. So you must use any methods to determine strongly connected components as a utility function meaning it should be in the private section. Moreover you use topological sort to determine connected components and not DFS.
Anonymous
Anonymous
Or rather #define SQUARE(x) ((x)*(x))
Yep, the macro is not right
Talula
#include <iostream> using namespace std; #define SQUARE(x) x*x int main(){ int x = 36 / SQUARE(6); cout << x; return 0; } can anyone explain this program ? why the output is 36 instead of 1
See macros are not actually functions, so what exactly happens is your code is replaced by the compiler to write what you have written... So if your macro is SQUARE(x) x*x Your int x = 36 / SQUARE(6) becomes int x = 36 / 6 * 6 This is why you'll have to add parenthesis Like SQUARE(x) (x*x) So it becomes int x = 36 / (6 * 6)
Pavel
#include <iostream> using namespace std; #define SQUARE(x) x*x int main(){ int x = 36 / SQUARE(6); cout << x; return 0; } can anyone explain this program ? why the output is 36 instead of 1
Tazz explained very well above what is the issue, but I want to add. Since you are writing code in 2021 and you're writing in C++ I will suggest not to use macros unless really necessary. They are error prone, can be very difficult to read and debug. In this example multiple things can go wrong. Imagine you put a function call with side effects inside your SQUARE macro call. E.g. SQUARE(getRandomInt(10)); The result will be not a square of a random int, but multiplication of two random ints. And the reader of the code will have hard time to understand what's going wrong. Imagine another situation, you put a call that executes some non-trivial logic inside: SQUARE(someExtensiveCalculations()). Congrats, it's created a performance degradation where nobody expected it. From the look of the code it won't be seen until someone will look up at the implementation of your macro. If you want something to be calculated at compile time you have constexpr functions, otherwise just use normal functions (they can be optimized pretty well also)
Anonymous
No. Piracy is not encouraged here.
artemetra 🇺🇦
i see different people use true/false keywords for bool variables and others use 0/1. afaik there is no technical difference, but which style is preferred in modern c++?
Anonymous
i see different people use true/false keywords for bool variables and others use 0/1. afaik there is no technical difference, but which style is preferred in modern c++?
true and false are always preferred. C++ and obviously C are the only two languages of inportance that support implicit conversion from ints to Boolean values. This was more of a legacy behavior and C++ supported it for backwards compatibility reasons with C.
artemetra 🇺🇦
okay, thanks!
Jasur Fozilov 🐳
https://pastebin.com/AGDsZM9k The answer is the same even if I remove the & sign in print_container. What is the purpose of using the & symbol?
Captain
https://pastebin.com/AGDsZM9k The answer is the same even if I remove the & sign in print_container. What is the purpose of using the & symbol?
& means an alias for the Vector it will avoid making copy of vector. It is advised to use const reference (const &) where the actual parameter is not getting updated.
Captain
If I don't use the & sign, it uses extra memory, right?
When you are using pass by reference it will be monolithic programming i.e it won't allocate memory for copies , in fact won't create copies at all which is efficient
Anonymous
Hello guys i have a question, are we allowed to get help if we have school work?
Anonymous
Even tho ive tried 😥?
touhou
Hello guys i have a question, are we allowed to get help if we have school work?
yes, show what you have tried and explain what's wrong or what you can't understand..
Viprr
Can anyone explain me what is bubble sort and selection sort??
touhou
Can anyone explain me what is bubble sort and selection sort??
https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/visualize/
Talula
i see different people use true/false keywords for bool variables and others use 0/1. afaik there is no technical difference, but which style is preferred in modern c++?
Actually the thing is 0 means false and 1 means true, but what happens is that in other languages that do not have a real boolean like BASIC, they use -1 as true and anything else is false. So it really doesn't matter much but it is a good practice to use true/false as it would help you to shift to other languages much easily and at the same time your program becomes easier to read.
Anonymous
Can anyone explain me what is bubble sort and selection sort??
https://en.wikipedia.org/wiki/Bubble_sort https://en.wikipedia.org/wiki/Selection_sort
Jasur Fozilov 🐳
Is the capacity in the vector only 2 powers?
Anonymous
Is the capacity in the vector only 2 powers?
It doesn't have to be. On gcc, they double the capacity everytime. So if you start out with a vector with capacity that is not a power of 2, then it will not be a power of 2 ever.
Sid
An error is coming at the time of compilation of my code
Sid
"Unable to find numeric operator 'operator"" Y' "
Anonymous
"Unable to find numeric operator 'operator"" Y' "
are you trying to create your "user-defined literals"?
Sid
BTW thanks for reply
Anonymous
Prblm solved bro
what it was?
Sid
👍
Sid
what it was?
I forgot something to put
Sid
That's why it coming
Voke
Hey guys how can I reverse an array of strings so that if I input an array with elements such as book and pen the output will be koob and nep
Voke
in c++ please😊
Golden Age Of
Hey guys how can I reverse an array of strings so that if I input an array with elements such as book and pen the output will be koob and nep
for_each(vec.begin(),vec.end(),[& ](string str) { return reverse(str.begin(),str.end());});
Golden Age Of
Try this, may be need to be corrected, im not at pc now
Anonymous
Greatings, Please suggest some professional resources to learn C++.
Sahil
Hi I'm new here, Can any one suggest how can i learn c++ from basic , from where to start, nd what are all the sources I will need?
Vikas
A book or YouTube tutorials will be helpful.