c++ vs c++

Oct 30, 2010 at 11:54am
hello

i have to diffrent book to start programming, one by dr.kris jamsa& lars klander and the other one by brain overland

now i want whats the different between these 2 codes?
1. dr.kris jamsa& lars klander book
#include <stdio.h>
void main(void)
{printf("fff");
}
2.brain overland book
#include <iostream>
using namespace std;
int main() {
cout << "fff";
return 0;
}

the programs doese the same thing but why the code its different?
Oct 30, 2010 at 12:02pm
The first one is C, though I'm not sure if void main is OK even in C..
The second one is perfectly fine C++.

Also, there are always many ways to do the same thing. There's nothing wrong with that.
Last edited on Oct 30, 2010 at 12:03pm
Oct 30, 2010 at 12:50pm
void main is what you call implementation depended. It will compile on some compilers but not all.
int main is the only true C and C++ way.

C and C++ standards allows for compilers to extent on the C and C++ standard for a given compiler. This means that you can use void main() if the compiler supports it, but only if your code will only and always be used with THAT compiler.

Unless the book is for a given C++ implementation, putting void main() in it is just BAD very very BAD!!!
Last edited on Oct 30, 2010 at 12:51pm
Oct 30, 2010 at 1:07pm
ok thx for the explanings...

Nov 7, 2010 at 5:47pm
Topic archived. No new replies allowed.