Sunday, July 13, 2008

C and C++ Language Tut

I am going to give you the codes for "Hello World" for C and C++ and I am going to explain what each line does.
(For those of you who do not know what "Hello World" is...It basic project that displays the text "Hello World".)


Code in C:
#include
int main(void)
{
printf("Hello World");}
#include (Includes something. Most C programs Include stuff so... The Codes they use work.)

int main(void) (It states the Main Function){ (It opens the code for the main function)
printf("Hello World"); (It prints "Hello World" in the program)} (It closes the code for the main funtion}

Code in C++
#include
using namespace std;
int main()
{
cout << "Hello World";return 0;
}
#include (Includes something. Most C++ programs Include stuff so... The Codes they use work.)
using namespace std; (Uses namespace std)
int main() (States the main function)
{ (It opens the code for the main function)
cout << "Hello World"; (It prints "Hello World" in the program)
return 0; (It states the end of the text printing. I think)
} (It closes the code for the main funtion}


You might notice that some of the code and definitions are the same between C and C++...
This is because C and C++ are pretty similar languages.

PS: I used these codes for my first C and C++ progams. I learned these codes from tutorials (These are very common codes you will see in C and C++ beginner tutorials, but this stuff is not just copy and paste. I didn't copy the explanation for each line, I wrote them myself.

- Crazy Monkey

No comments: