It's programming time!/C++/int main()

From Create Your Own Story

#include "stdafx.h"
#include <iostream>

int main()
{
std::cout << "Hello world!" << std::endl;
return 0; }

int main()

Three elements here:

int
main
()

So, first, we have int. int stands for "integer", or a number. Gah! Math! Yeah, programming is full of math...

Anyways, for the case of Hello World, basically we just want to find a way to tell the program "I am done", so it does not need to keep running. We will see that more in return 0;, so I will not explain how that works here.

Anyways, the int says "We will have an integer". For different data types, you can check the data types table.

main means this is the main function. What is a function? It is something that tells the program what to do. Normally, the main function will tell it the main parts, but sometimes we will have other functions so we do not need to stick everything in main. It makes it rather long and ugly, and hard to find problems with.

Last, we have the (). Basically, this is here to tell it to "get stuff" from the operating system before it starts running our program. Like, for my scooter and key example, I would need to know where my scooter is located before I can use my #include "scooter keys". So, I need to find out where I parked it. int main(locate scooter). While riding the scooter has nothing to do with where it is parked, it does have something to do with how I can get to it to ride it in the first place.

So, all clear? Guess you should click another line above=P

Personal tools