First Program in C/C++

First Program in C/C++
Now it is time to journey to our favorite language C/C++ as we've leanned the fundamental about this language at the previous discussion and in this section, we will start coding in C and C++ language. It is better to start with printing something on the screen as a first program. Yes, we will start from beginning but before starting we should know the basic requirements to start C/C++ programming. Now, at first we'll know the basic requirements to start this interesting programming language.



What we Need
  • Firstly, we need an editor where will put our symbolic word of C/C++ language. Now a days a number of editors like TC(Turbo C++), Netbeans, Eclipse etc are available to edit the C/C++ code. Even we can code at Window's notepad and compile the program with C/C++ SDK but it will be so hardy work. So we'll use the most popular(I think) integrated package named Microsoft Visual Studio 2010. Coding with Microsoft Visual Studio 2010 is as easy as to play with a cat.
  • Secondly, we need a compiler which will interpret the written C/C++ code. So, C++ SDK(C++ Software Development kit) is the first requirement. On the other hand, if we use Microsoft Visual Studio, we'll get both the editor and the compiler(SDK) as a integrated package. Now we'll see how to program with Visual Studio 2010.  

Preparing Microsoft Visual Studio 2010 

To use Visual Studio 2010, we need to download and install it with our system. So, I will recommend you to download and install Microsoft Visual Studio 2010 in your system. Here I'll show you how to start Visual Studio 2010 step by step:
  • Start Visual Studio 2010 from start menu. When started, you will see start page like below figure... 

Start Page

  • Go to File>>New>>Project. New Project window will appear. At the left pane, select other languages. Then select Win32 Console Application and give the application name as FirstProgram(as I provided) and click OK button like this...

New Project Window

  • Now you will find Win32 application Wizard window. Here nothing to change, just click Next button like this...
Application Wizard

  • Here is the last setting named Application Setting window. From the application type category select Console Application radio button and from additional Options select Empty Project check box. Now Click Finish button.
  
Application Setting

  • You'll now find nothing but only a Solution Explorer and a Toolbox window like the below figure. Here we'll add source file to edit C/C++ code. 
Just starting page

  • To add source code, go to Solution Explorer and right click on Source Files folder. Now Follow Source Files>> Add>> New Item and left click. Then you'll see Add New Item window like the below figure where we'll use C++ file only. So, select C++ file(.cpp) and put your .cpp file name say test in the Name textbox. Now Click Add button.   
Add new item window

  • After a few moments, you'll find that the test.cpp file has been added in the Source Files folder and a window named test.cpp is discovered at the middle window of the Visual Studio 2010. This is our desired window or editor where we'll put our C/C++ code. Now the Visual Studio 2010 IDE will appear like this...... 
    Last Window


    Now we are ready to start  coding with Visual Studio 2010 IDE. At the following section, we'll put our first program code in the test.cpp file.

    Writing the First C/C++ Code

    All the preparations to start our first program have been taken from the above section. Now we'll write our first program which will show a message on the window's command line window like "Hello World".  Now put the following code in the test.cpp file.

                     #include<stdio.h>
               void main()
               {
                  printf("Hello World!\n");
               }

    This is our first program which will show Hello World! message. To show this message, we need to Compile and Run the test.cpp file. To do so, press Ctrl+F5 and you will find the desired output on the screen like this....

    Output


    At last, we are successful to edit and run our first program but you are so confused that what the hell is happening here! Don't worry, I'll discuss the every line of the code step by step at the next tutorial. So, keep it up........  

    No comments:

    Post a Comment