Are you looking forward to writing your first program in C++? When you are writing a C++ file, there is a format that you need to follow before executing the result. You should remember that every language has specific syntax and rules to follow. If you miss those rules, then your program will not be executed. In C++, every program must have a main function. Without the main function, it is impossible to run a program.
There are certain things that you need before understanding the C language. You must have a compiler on which you can write a code. Your first step toward learning C language is to install a compiler. After installation of a compiler, start a new project. Click on the file button in the menu bar and click on the new project. It is your first C program, so type "My first program" in the name tab, and click next. Do not make any further changes and click finish. The project has been created. Now, the next step is to add a source file. Click on the file button again in the menu bar and click new source file. After clicking it, add the name of the file. The name of the file must end with ".c" or ".cpp" extension. The meaning of ".c" extension is that the file belongs to C language, while ".cpp" means C
The first thing that is needed for a C++ program is the header file. It is necessary because it contains functions that can help in executing built-in functions. For example, if you want to print on the compiler screen, then you need "iostream" file. So, your first step is to add the header file. Now, the next step is to add the main function. Write it after the header file and start the parenthesis. The body of the main function contains all the functions that you want to execute in the program. As, it is your first program, so write "cout<<"My first hello world program"; "Cout" function in C++ is used to display the output on the console screen. You should also remember the syntax. Every line in C++ language ends with a colon. If you forget to add, the compiler will be unable to execute the program. Close the main function and click on compile. If the program is compiled successfully, click on the run button and a screen will appear with the output "My first hello world program".
Post a Comment