31.3.08

many people thought main would be the first function to be called.
But there are some exceptions where other function get called
before main actually called.


class mine {
public:
mine()
{
cout<<"Constructor called \n";
}
};

mine obj1;

int main() {
cout<<"we are in main";

return 0;
}


after running this first constructor will be called later main executed.

7.3.08

passing arguments

Passing arguments to function.

Let say
int fun ( int ) ;
is the function prototype.

Now function call was made like this.

fun(x++);

This is not good practice.
In the above call our intension is to pass the incremented value of 'x',
but it pass the value of x not x+1.The best practice is, fun(++x).

Code:

int main()
{
void test_fun(int);
int num=10;
test_fun(num++);
return 0;
}
void test_fun(int num)
{
printf("NUM=%d", num);
}

Output is : NUM=10

print 1 to 100 without using loop

Printing from 0 to 100 without using
any loop.

we can do this using recursion.

Code:
void print()
{

static int x;
if (100 == x )
return; /* or use exit call*/

printf("%d", x++);
print(x);

}