Thursday, April 15, 2010


using namespace std;

int fact(int n){
if(n == 1){
return 1;
return fact(n-1)*n;

int main(){
return 0;

for this program's output, you can see it as ((((((1)*2)*3)*4)*5)*6)=720.

Commend line arguments!

argc hold amount of element which you type in commend line.

argv will hold the content which you type in commend line, for example:

If you type "argc.exe Hello World !" in your commend line, the argc will set to 4. argv will content "argc.exe Hello World !".

If you run program like: #include
using namespace std;
int main(int argc, char* argv[]){
int i;
for(i=0;i cout< }
return 0;
The output: argc.exe

Sunday, April 11, 2010

Difference between public, private, protected inheritance

Public:inherite the protected members as preotected in drived class and pubic members wiull be public in derived

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

The try, catch, and throw Statements

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:

  1. Control reaches the try statement by normal sequential execution. The guarded section within the try block is executed.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Saturday, March 13, 2010



class LinkedList;

class Node{
int data;
Node* next;
Node(int data , Node* next = (Node*)0);
friend class LinkedList;

class LinkedList{
Node* head;
Node* tail;
void add(int data);
int remove();
bool IsEmpty();


#include "linkedlist.h"

Node::Node(int data, Node* next){
this->data = data;
this->next = next;

head = tail = (Node*)0;

while(!IsEmpty()) remove();

LinkedList::add(int data){
Node* temp = new Node(data, tail);
tail->next = temp;
tail = temp;
head = tail = temp;

bool LinkedList::IsEmpty(){
return !tail;

int LinkedList::remove(){
int data = 0;
return data;

I'm not sure this is correct !

Queue's Operations from the C++ Standard Template Library

bool empty()
Returns True if the queue is empty, and False otherwise.

T& front()
Returns a reference to the value at the front of a non-empty queue. There is also a constant version of this function, const T& front().

void pop()
Removes the item at the front of a non-empty queue.

void push(const T& foo)
Inserts the argument foo at the back of the queue.

size_type size()
Returns the total number of elements in the queue.

va_list,va_start, va_arg, and va_end

va_list: Type to hold information about variable arguments

This type is used as a parameter for the macros defined in cstdarg to retrieve the additional arguments of a function.

Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for the va_start, va_arg and va_end macros.

va_start is in charge of initializing an object of this type, so that subsequent calls to va_arg with it retrieve the additional arguments passed to the function.

Before a function that has initialized a va_list object with va_start returns, the va_end shall be executed.

: Initialize a variable argument list

void va_start ( va_list ap, paramN );

Initializes the object of type va_list passed as argument ap to hold the information needed to retrieve the additional arguments after parameter paramN with function va_arg.

A function that executes va_start, shall also execute va_end before it returns.


Object of type va_list that will hold the information needed to retrieve the additional arguments with va_arg.
Parameter name of the last named parameter in the function definition.

va_arg: Retrieve next argument

type va_arg ( va_list ap, type );

This macro expands to an expression that has the type type and the value of the next argument in the variable arguments list.

The next call to this macro will expand to the following argument in the same order as passed to the function.

Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.

Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the amount of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.


Object of type va_list with information about the additional arguments an their retrieval state. This object shall have been initialized by an initial call to va_start before the first call to va_arg.
A type name. This type name is used as the type of the expression this macro expands to (i.e., its return type).
For a type expression to be suitable for its use with va_arg it must be such that when an asterisk (*) would be appended to its right the resulting expression would be a valid pointer type to a type object.

Return Value

Returns the next additional argument as an expression of type type.

va_end: End using variable argument list

void va_end ( va_list ap );

Performs the appropiate actions to facilitate a normal return by a function that has used the va_list object ap to retrieve its additional arguments.

This macro should be executed before the function returns whenever va_start has been previously used in that function.


va_list object previously initialized by va_start in the same function.