using namespace std;
int fact(int n){
if(n == 1){
return 1;
}
else{
return fact(n-1)*n;
}
}
int main(){
cout<<
fact(6)
return 0;
}
for this program's output, you can see it as ((((((1)*2)*3)*4)*5)*6)=720.
Public:inherite the protected members as preotected in drived class and pubic members wiull be public in derived
class
Protected:pubic and protecated members of the base class will become protected in derived class
Private:pubilc and proteacted members will become private in derived class
If we have class a and class b:
for Virtuality Mode public
class a class b
private =! private
public = public
protected = public
for Virtuality Mode private
class a claas b
private =! private
public = private
protected = private
for Virtuality Mode protected
class a class b
private =! private
public = protected
protected = protected
try {
// code that could throw an exception
}
[ catch (exception-declaration) {
// code that executes when exception-declaration is thrown
// in the try block
}
[catch (exception-declaration) {
// code that handles another exception type
} ] . . . ]
// The following syntax shows a throw expression:
throw [expression]
Execution proceeds as follows:
Control reaches the try statement by normal sequential execution. The guarded section within the try block is executed.
If no exception is thrown during execution of the guarded section, the catch clauses that follow the trycatch clause following the try block are not executed. Execution continues at the statement after the last block in which the exception was thrown.
If an exception is thrown during execution of the guarded section or in any routine the guarded section calls (either directly or indirectly), an exception object is created from the object created by the throw operand. (This implies that a copy constructor may be involved.) At this point, the compiler looks for a catch clause in a higher execution context that can handle an exception of the type thrown (or a catch handler that can handle any type of exception). The catch handlers are examined in order of their appearance following the try block. If no appropriate handler is found, the next dynamically enclosing try block is examined. This process continues until the outermost enclosing try block is examined.
If a matching handler is still not found, or if an exception occurs while unwinding, but before the handler gets control, the predefined run-time function terminate is called. If an exception occurs after throwing the exception, but before the unwind begins, terminate is called.
If a matching catch handler is found, and it catches by value, its formal parameter is initialized by copying the exception object. If it catches by reference, the parameter is initialized to refer to the exception object. After the formal parameter is initialized, the process of unwinding the stack begins. This involves the destruction of all automatic objects that were constructed (but not yet destructed) between the beginning of the try block associated with the catch handler and the exception's throw site. Destruction occurs in reverse order of construction. The catch handler is executed and the program resumes execution following the last handler (that is, the first statement or construct which is not a catch handler). Control can only enter a catch handler through a thrown exception, never via a goto statement or a case label in a switch statement.