Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is it better, from complexity eye of view, to call a function and return its value to another function
a = foo();
bar (a);
Or to make a nested call?
bar(foo());
Indeed, I am making this millions of times.
If it depends on something else, please mention it.
You should go for clarity - the compiler should optimize the temporary away. But if it's critical, benchmark and look at the assembly code.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
if(cout<<"h"){}
this gives me an output
h
Any idea why, I have tried many variations of it and it still works.
That's because the if statement needs to evaluate the condition you give into it, plus, streams are implicitly convertible to bool.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Develop an algorithm that can be used to determine whether a Stack object S has exactly one element.
I am not a programmer, I choose this course as an elective to see if I would be interested. I don't know where to begin with this question.
You most likely want to check the documentation of C++ on stacks. This took no time to find:
http://www.cplusplus.com/reference/stack/stack/size/
Your function has to return stack.size() == 1. If the question is asking to develop an algorithm based on the size in memory the stack size allocates then it's slightly more involved.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
A simple example of how you would structure this would be particularly useful.
This is how I would do it:
MyMotor is an instance of the class Motor. This class has four functions idle(), accelerate(), flat(), decelerate(). (I assume you know how to build a basic class with private members and its constructors)
Then in main(), I create MyMotor and control it based on states. States can be controlled/monitored using Boolean Values. Whatever state I am in and whenever, certain function will be called.
Next time give it a try before you ask here, in order to get better responses.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there is any specific reason behind undefined behavior in C and C++?
Why are some features left undefined?
For some part at least, it was to allow a more efficient implementation.
A simple example: Function parameters. Their evaluation order in unspecifed, because some architectures could work better depending on how they made the calculations or the calling convention (registers, stack, etc.)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm making a small game and I don't know whether I should have the majority of the statements in the main function or instead just put them as void functions in my player object (I'm not really returning anything other than boolean values throughout each iteration).
In general, you should aim for your main() to be a bridge between the execution environment (the OS) and the system that you implement. This means that main should "crack" the command-line parameters, and then promptly pass control to the method that instantiates top-level objects and runs your system.