c++ vs c++

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?
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
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
ok thx for the explanings...

Topic archived. No new replies allowed.