Header Ads

Download and install Dev C++

Dev C++ download (Devshed C++) from https://sourceforge.net/projects/orwelldevcpp/. You can fee download dev c++ and install (You may use Dev C++ online) 

Create C++ file

Open Dev C++ and create new file

create cpp file

Write first C++ program

first cpp program

Save file by pressing Ctrl + S OR by File => Save and type file name. Now compile program and run. You can perform compile and run separately. However, I suggest to compile and run together by following three ways:- 
  • Press F11 from keyboard
  • Go to Execute => Compile & Run
  • Click on Compile & Run icon

compile c++
first cpp program output

Let us explain program line by line

Line 1:

#include is C++ header file from C++ library. It provide us cout word to display output (and also cin to get input). C++ contains several header files and we can use them. Iostream C++ header file is used to get input from user and display output to screen 

Line 2:

using namespace std c++ let us to use cin and cout word in simple direct way. Without writing it, we have to write std:: with all cout’s and cin’s in the program like std::cout<<”Hello World!”; 

Line 3:

int main() This is main function of program where control start execution. 

Line 4:

curly brackets {} is body of this function. Program start its execution from the body of main function. Don't worry if you don't understand how #include , using namespace std and int main() works. It will be covered in coming tutorials. 

Line 5,6:

{ cout << "Hello World! "; } { is open curly bracket to start body of main function. cout c++ used together with the insertion operator (<<) to output/print text on screen. In our example it will output "Hello World". } is close curly bracket to close main function. 


All statements of C++ end with a semicolon ; 


You can insert empty lines (white spaces) between code line because c++ compiler ignores these lines. cin strings is used to get user input, will be covered in next lesson

Post a Comment

Previous Post Next Post