|
Rance Necaise
Visiting Associate Professor of Computer Science |
||
|
|
||
|
|
C++ Primer For Java Programmers The Main Function« | Table of Contents | Variables and Data Types »
All programs must have a starting point for execution. In both Java and C++, the first statement executed is the first statement within the program’s // Hello world program in C++. #include <cstdio> int main( int argc, char *argv[] ) { printf( "Hello World!\n" ); } and the equivalent in Java. // Hello world program in Java. class MyProgram { public static void main( String [] args ) { system.out.println( "Hello World!" ); } } The two arguments to the main C++ routine are used to access the command-line arguments. If your program has no need for command-line arguments, you can use the following version of the main routine instead. // Alternate form of the main() C++ routine. #include <cstdio> int main() { printf( "Hello World!\n" ); } |