Friday, January 26, 2018

Keeping up with C language

Start your first Program

To start writing any program in C you should pass through many steps. The first step is to write your code on any platform that works with C language. Well I suggest visual studio. You can also find several other applications like Eclipse, Netbeans, Code::Blocks, and much more.
For me, working with visual studio for C, and with Netbeans for Java, python, and others was the best. The following link will help you choose any application you like: 
https://www.quora.com/Which-software-is-used-to-run-C-C++


All programming languages depends upon compiler and IDE to give results. So what are the stages that C program passes through before showing results.

Stages of Compiling a C program


The first stage is the preprocessing stage. To write any code the first step you need is to include some header files inside your code. For now, I will use => #include <iostream>. As its name includes, the compiler will call the header file; iostream in our case. This header file is used will let you use cout or cin. Yeah, I know it sounds weird, but trust me by following the steps you'll make your first program. Well, the first program for us now is to output Hello world on screen. Huh, this is the very first program for any programmer.

Every program starts from main. So after the include section you should include int main() in any C program. If not, your program will not give any result. The code would be like this:


After writing the code, it's time to move for the next stage called compilation. In this phase the preprocessed code is translated to assembly language in order to target the processor architect.
The assembly language will translate the assembly instructions to machine code; this phase is called assembly.

The object code generated in the assembly stage is composed of machine instructions that the processor understands but some pieces of the program are out of order or missing. To produce an executable program, the existing pieces have to be rearranged and the missing ones filled in. This process is called linking. Source: https://www.calleerlandsson.com/the-four-stages-of-compiling-a-c-program/#linking



Explanation


Inside the video, a new header file was included (stdio.h). Remember this header file are already defined and can be used easily. The second thing that differs from the first program is printf instead of cout, but both of the are used for the same reason.
Obviously, the reason was to show the sentence inside the double quotes on your black window.
It's also important to know that using name std is used with #include <iostream>. 
Congratulation !! Your have successfully compiled you first program !!

To know more about C/C++ please don't hesitate to buy the book in the gadget. You'll find there many programs where you can start anywhere and any time and you'll see output for each one of them.

IMPORTANT

Make sure to buy your free kindle book now.


No comments:

Post a Comment