The factorial of 0 is indeed 1, but that's not really a problem. The problem is that the factorial of 20 is 2,432,902,008,176,640,000 and that's the largest factorial that will fit in a 64-bit integer. With only 21 factorials (including 0) to play with, a simple lookup table would be a lot quicker than calculating each of them separately.
unsigned __int64 factorial(unsigned num)
{
switch (num)
{
case (0):
case (1): return 1;
case (2): return 2;
case (3): return 6;
case (4): return 24;
case (5): return 120;
//....
case (20): return 2432902008176640000;
}
return 0; // indicates error!
}
To calculate them individually, use the following function:
unsigned __int64 factorial (unsigned num)
{
if (20<num) return 0; // indicates error!
unsigned __int64 result= 1;
while (1<num) result *= num--;
return result;
}
To accommodate factorials greater than 20 you could use a 64-bit double-precision float, however the results will be an approximation rather than precise and the risk of overflowing still exists. The best solution is to employ a user-defined, dynamically-sized type specifically designed to cater for large integrals (although they'd no longer be integral, of course). There are many libraries available to cater for this but, personally, I use the GMP library as it's one of the fastest available.
What is an address in C plus plus programming?
An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.
How do you determine when a stack is empty in c plus plus?
#include<iostream>
#include<stack>
#include<cassert>
int main ()
{
std::stack<unsigned> s;
assert (s.empty()==true);
s.push (42);
assert (s.empty()==false);
s.pop ();
assert (s.empty()==true);
}
Is this run time checking mechanism done by c plus plus?
There is no such thing as a runtime checking mechanism in C++. The compiler can only catch compile time errors. You must provide any additional checks yourself, to handle any exceptions that may occur at runtime. Failure to handle an exception results in an exception error at runtime. The end result is that the program crashes but, if debug information is available, you can easily locate the source of the exception and thus determine how best to provide a handler for it. But this mechanism is not handled by C++ itself, it is handled by the debugger.
What are three functions of a virtual assistant?
Virtual Assistants can manage a variety of functions related to your business or personal needs from responding to email to managing your website.
Many virtual assistants specialize in particular areas such as wordpress or bookkeeping. Others are more generalists and can handle basic administrative tasks.
Many virtual assistants work with a team that can handle virtually any task you throw at them.
Can you tell me a C program to find if the strings are equal using pointers?
It is called strcmp, part of the standard run-time library. Returns 0 if the two strings are equals, non-zero otherwise.
What is the difference between instantiation and initialization in C plus plus?
Instantiation is creating the instance of the variable/object . While Initialization is to provide the variable with some value.
int i; // i is an instance of an integer
i=10; //initialised with the value 10
Is Microsoft Visual C plus plus IDE a good product?
It is a good product, albeit a pricey one. However the C++ implementation is non-standard. If you're coding purely for Windows platforms and do not require portability with another compiler then VC++ is hard to beat. But if you require cross-platform and cross-compiler capability, you'd be best advised to use a generic implementation that fully complies with the ISO standard.
What is the lowest subscript of an array in c plus plus?
The lowest subscript of an array in C, or C++ is 0.
Explain any two advantades of c plus plus over jaca?
I prefer Java; it has been greatly simplified, and made safer, as compared to C++. However:
1. In any situation where there already is a large amount of source code in C or C++, it would be a significant investment to change to another language, even Java, despite its superficial similarities. So, in such a case, compatibility with existing code would be an advantage. Of course, if you have done lots of programming in Java, it would be the other way round; and if you are starting a new programming project, this argument is irrelevant.
2. Code written in C or C++ would be faster and the compiled version would be smaller. This can be critical in some situations.
How do you represent switch case statement in algorithm?
i dont know aghar mujay ata to ma net pay search karta
Why are there no plus size Anime characters?
there are ^_^ check out akimichi chouji (in fact the whole akimichi family) from naruto jidanbou, komamura, etc from bleach and theres one in one of the seasons from dijimon but i cant remember his name (i didnt watch it a whole lot) and there are others as well... (hope this helped) Janitor1: Well, there are, like chouji and the 2nd division vice-captain dude from Bleach, but they just aren't that popular, because we all know that people prefer skinny girls and guys with 6 packs -.- Such a shallow world we live in >.<
What is difference between plus plus j and j plus plus in programming?
++j is the prefix increment operator while j++ is the postfix increment operator. The same applies to --j and j++, the prefix and postfix decrement operators.
The difference between prefix and postfix increment is not the operation itself -- they both increment the operand, which is j. The difference is in the evaluation of that operation -- the value that is returned by the operation.
Prefix will increment j and return a reference to j. Postfix essentially copies j, increments j, and returns a reference to the copy.
In other words:
If j is 1, ++j increments j (so j is 2) and returns a reference to j (which is now 2).
If j is 1, j++ copies j (which is 1), increments j (making it 2) and returns the copy (which is still 1).
When j is a primitive (such as int), no copy is actually made (the return value is pre-emptied by the CPU). Thus there is no difference in terms of performance, the only difference is the return value.
However, when j is a non-primitive, such as a class type, the postfix operator must physically copy the class instance, increment the original instance and then return the copy. As such there will be a performance penalty. If you have no use for the return value, performance will be improved if you use prefix rather than postfix. The more complex the class, the more obvious the difference will become when repeatedly incrementing a class in a loop.
although there is no difference in performance with primitives, it is good practice to use the prefix increment at all times, and use postfix only when you actually need the original value of the operand. Once you get into the habit of using prefix by default, you'll avoid making unnecessary copies of classes other than when you actually need to.
In other words, use for( int x=0; x< 10; ++x ) rather than for( int x=0; x<10; x++ ), regardless of whether x is a primitive or a class type. In both cases, the return value is ignored, but it still exists.
To capture the return value, you must assign it to another variable. Such as int y = x++, or use the operator in a compound expression (where the result is used as part of a larger expression).
Postifx increment is often used with pointers and arrays, to assign a value to the current element being pointed to before advancing the pointer to the next element:
int x[2];
int * p = x;
*p++ = 1; // assigns x[0] and then advances to x[1].
*p = 2; // assigns x[1].
Thus x[0] is 1 while x[1] is 2.
Why do you need runtime polymorphismis inheritance necessary for it?
Runtime polymorphism is required because accessing the runtime type of an object is expensive. And yes, inheritance is required for it because polymorphism is enabled through virtual functions. It is not the programmer's responsibility to determine the runtime type of an object because that information should be provided by the object's own virtual table. Thus when you implicitly invoke a virtual method of the base class, you rightly expect most-derived method to be executed, even when you cannot know in advance the exact type of the derivative -- all you know is that it is a type of base class. And that's all you need for polymorphism to work. If you ever find yourself having to turn on the runtime type of an object in order to invoke one of its methods, then you need to seriously consider redesigning your classes. How can your code possibly cope with a runtime type it has no knowledge of, such as a derived object of a class created by a third-party? In those instances you would have no way of knowing what specific methods were available. But with virtual methods there is no need to know. You simply invoke the generic virtual methods of your base class and you automatically get specific behaviour; all your derivatives do whatever they've been implemented to do, whether it is to invoke the base class method explicitly, or provide an override, or indeed both!
What must an opening brace in a C plus plus program be?
An opening brace must be terminated with a closing brace in C++. Braces are used to enclose code blocks and initialiser lists.
Are the private access specifiers in Java and C plus plus the same?
No.
In Java, the private access modifier restricts member access to the class in which the member is declared. But in C++, private members are also accessible to friends of the class in which they are declared. The rough equivalent in Java would be package private access.
Not that Java doesn't have access specifiers, it has access modifiers. When no modifier is specified, default access is implied, which is package private for classes and public for interfaces.
RTTI means run time type identification. It is the process of identifying the type of an identifier or an object during runtime which is not known during compile time. Through this, we can hide the implementation details of a particular identifier or an object at the user level during programming so that it ca be distinguished during runtime and used further.Object persistency is acheived through RTTI
What is the name of the C structure type?
The type is struct. The name can be any valid variable name that is not a keyword or other reserved name.
What is the difference between C and C plus plus prototypes?
The only difference is that C does not use nor require prototypes. C++ does because all functions and types must at least be declared, if not defined, before they can be used.
Which Company To develop c plus plus language?
While there are many companies and organisations implementing C++, language development is the sole responsibility of The C++ Standards Committee, or WG21 as they are officially known (ISO/IEC JTC1/SC22/WG21). Bjarne Stroustrup, the original developer of C++ and a founding member of the committee, currently sits as the Chair of the Evolution Working Group.
How relational operators represented in c plus plus?
The relational operators are == (equal), != (not equal), < (less than), <= (less than or equal to), > (greater than) and >= (greater than or equal to). All relational operators are boolean, returning true or false depending on the l-value relationship with the r-value, with respect to the operator.
How do you install the mfc feature in visual c plus plus 2005 or 08 or 10?
MFC is installed by default. To use it, start a new project and select MFC Application, MFC DLL, or MFC ActiveX Control, as appropriate, and follow the application wizard prompts.
What are the C plus plus translator used?
If you mean interpreter, there is no such thing. C++ is a compiled language. This means that the source code is compiled to produce object files which are then linked to produce a native machine code executable.
Interpreted languages such as BASIC work differently. Rather than compiling the code to produce an executable which can then be run, the code is translated into machine code one line at a time by another program, the interpreter. Once a line of code is interpreted, it is executed, then the next line is fetched and interpreted. However, the previous line is lost and must be reinterpreted the next time it is encountered. As a result of this, interpreted programs do not perform as well as compiled programs. However they can be executed immediately without waiting around for compilation, which can take many minutes when the program is large.
Languages such as Java are a hybrid of both compilation and interpretation. The Java compiler compiles the source code into byte code which is suitable for interpretation by any Java virtual machine. This is faster than interpretation alone, but not as fast as compilation alone but, once compiled, Java programs can be executed on any hardware that supports a JVM (which is pretty much everything out there today). By contrast, C++ must be recompiled separately upon each target platform.