Environment to write code:

Environment to write code means that the environment where we can write and run (compile) our code. To write code, we need a text editor. We need a compiler to compile our code which will convert our code to machine understandable code.

Compiler:

Compiler translates instructions written in a high-level programming language into the equivalent machine code. There are many compilers which are available in the market. For C language, you can use gcc which is good as far as 2024.

Integrated Development Environment (IDE):

IDE functions as an editor as well as a compiler. There are different IDEs available like:
  • Visual Studio
  • Code Blocls
  • Eclipse
  • VS Code
  • CLion

These are all free and you can use any of these to run your code.

Note: Online Integrated Development Environments (IDEs) are also available but they have limited functionality. Download the Integrated Development Environments (IDEs) listed above for better experience.


After setting up the environment, open the new file. Write the following code and save it with ".c" extension.


syntax.c
#include <stdio.h>

  int main() {
    printf("Hello World!");
    return 0;
}

Flowchart for Code Compilation:


flowchart

Flowchart Explanation:

  • Source Code


    Source code is the code which we write using a programming language like C, C++, Java, Python etc.

  • Preprocessor


    Removes all the comments and added header files and does stuff like that and send code to the compiler for compilation.

  • Compiler


    Compiler compiles the code and convert the code into assembly code. For C language, gcc is available.

  • Assembler


    Assembler converts the assembly code into machine code. Assembler gives .obj file as output.

  • Linker


    Linker links static libraries with our machine code and makes it executable. Linker gives .exe file as output.

Components of C Code:

  • Header Files : They provide functionality.
  • Main Function : All code is written in Main function.
  • Return Statement : It returns from the main function.

We will understand this code in the next chapter.
Your code should be syntactically correct so that it will execute without any error.