Create Your First C++ Program
Don't worry if you don't understand everything right now. Everything will be cleared as you proceed with further lessons. Just keep practicing every program until you are able do it with your own. If you get any error, check your source code with this one carefully. Fix your error then compile and run it again.A Small C++ Program Example
#include <iostream>
int main ()
{
std::cout << "Hi! Hello! Wassup!";
return 0;
}
What are header files (Preprocessor Directive) ?
The statement that begins with #include are known as header files. It is also called as preprocessor directive. When you start the compiler the preprocessor runs first. The preprocessor will be discussed in detail in further chapters. The command #include is a preprocessor instruction that says, "What follows is a file-name. Find that file, read it, and replace it right here." The angle brackets around the file-name tell the preprocessor to look in all the usual places for this file. For example, the file iostream (input-output-stream) is used by cout which displays the output. What is function ?
Every function starts from the opening brace ({ ) and ends with closing brace ( }). Opening and closing brace together are also called as a block. A block of code that performs one or more action is called function.What is main function ?
In actual program starts from main function. Main function is also known as primary function or building block of the program. It is compulsory function.Every C++ program has main function. Every function is called by other function except for main function. Main is a special function which is called directly when your program starts. The return type of main is int, which means it should return an interger value. The main function returns value to an operating system. In this case it return 0 to the operating system. It is used to determine success or failure of the program. It will be discussed in detail in later chapter of functions. Its okay if you don't understand it now but just understand that when you write "int main()" then it becomes compulsory to write "return 0;" before the closing brace of main.