Hello, World!

Download source: hello.zip.

hello1.c

Here is the classic C version.

1: #include <stdio.h>
2: 
3: int main(int argc, char *argv[])
4: {
5:         printf("Hello, World!\n");
6:         return 0;
7: }
8: 

Compile and run as follows

1> gcc -o hello1 hello1.c
2> ./hello1
Hello, World!

hello2.c

Here is “Hello” with arguments.

1: #include <stdio.h>
2: 
3: int main(int argc, char *argv[])
4: {
5:         char *sal = "World";
6:         if (argc>1) sal = argv[1];
7:         printf("Hello, %s!\n",sal);
8:         return 0;
9: }

Compile and run as follows

1> gcc -Wall -o hello2 hello2.c
2> ./hello2
Hello, World!
3> ./hello2 ece449
Hello, ece449!

hello3.cpp

Here is “Hello” in c++ with iostreams

1: #include <iostream>
2: using namespace std;
3: 
4: int main(int argc, char *argv[])
5: {
6:         cout << "Hello, C++ World!\n";
7:         return 0;
8: }

Compile and run as follows

1> g++ -Wall -o hello3 hello3.cpp
2> ./hello3
Hello, C++ World!

helloQt4

Finally, we have “Hello” using Qt (see Qt.nokia.com)

01: #include <QApplication>
02: #include <QLabel>
03: 
04: int main(int argc, char *argv[])
05: {
06:     QApplication app(argc, argv);
07:     QLabel *label = new QLabel("Hello Qt!");
08:     label->show();
09:     return app.exec();
10: }

The code executes in its own window, shown below.

The default size of the window is small and the window may be hard to find on the display. It was resized before taking the screen shot above.


Maintained by John Loomis, last updated 3 February 2010