C/C++ Hello World Tutorial

Status
Not open for further replies.

Baljeet

Member
Jan 31, 2011
76
0
This tutorial I aimed for those who would like to learn to do basic output in c and in c++. This is very easy and for begginers, fun.

Let's get down to business:

C Version:
Code:
#include <stdio.h>

int main() {
     printf("Hello World");
     system("PAUSE");
     return 0;
}
Explanation:
#include <stdio.h> - This piece of code basically means that you want to include the Standard Input and Output header file. Header files are to be included in pretty much all your code seeing as this is where the "actual" code is.

int main() { - This opens a function called main that returns and integer. All applications much have a main function.

printf("Hello World"); - This prints to the screen "Hello World"

system("PAUSE"); - Basically stops the application from closing seeing as it has already ran the code we wanted it to run. Another way of doing so is: getchar().

return 0; - This is returned stating the application ran with no problems.

} - Closes the main function.


C++ Version:
Code:
#include <iostream>

int main() {
     cout << "Hello World";
     system("PAUSE");
     return 0;
}
Explanation:
#include <iostream> - This piece of code basically means that you want to include the Input and Output Stream header file. C++ header files do not need the .h extention. Header files are to be included into almost, if not, all applications, seeing as they hold the "real code".

int main() { - This opens a function called main that returns and integer. All applications much have a main function.

cout << "Hello World"; - This prints to the screen "Hello World"

system("PAUSE"); - Basically stops the application from closing seeing as it has already ran the code we wanted it to run. Another way of doing so is: getchar().

return 0; - This is returned stating the application ran with no problems.

} - Closes the main function.

All Credits goes to one who really made this...
 
Status
Not open for further replies.

Users who are viewing this thread

Top