Monday, September 25, 2006

Print something outside a main!

hi All!

Came after a long break! Cant make time actually in this boringly busy schedule of my job! Dint read anything technical as such but couldn't leave this blog inactive for this long! Hence posting something interesting for those who dont know about this!

I ask you to print something, say yo name through a program!
you write,

#include < iostream >
#include < iomanip &gt
using std::cout;
using std::endl;

int main()
{
cout << "Sandesh" << endl;
}

Simple right???

Now i ask you to print yo name without writing any output statements in main. You say, Fine! I'll declare a function, write the output statement over there n there you have yo program. i.e.,

#include < iostream >
#include < iomanip &gt

using std::cout;
using std::endl;

void foo()
{
cout << "Sandesh" << endl;
}

int main()
{
foo();
return 0;
}

Haha! I dint say that way! I want neither any output statements in main nor any functions using such things in main!!

Thinking??? Here goes the solution!

#include < iostream >
#include < iomanip &gt

int foo()
{
cout << "Sandesh" << endl;
return 0;
}

static int x = foo();

int main()
{
return 0;
}

Sumthin interestin right???