Banker Learning C: Part 1
Tags: c, tutorial
Published: 2021-12-01 19:02:52

Back to learning. I will not list some processes here like installing **IDE, compiler** etc. but provide useful links, as Internet has already better resources in this topic I can ever produce.

##Compiler?!

Most of us who are not from CS background find the idea of compiler very hard. The main reason is, we start with a programming language like **`Python`** or **`R`** that doesn't require learning this concept. These languages make writing and executing code very easy. For **Python**, steps are:

- Go to the [download](https://www.python.org/downloads/) page and download the package based on your OS,
- Run Python from the OS(for Windows PowerShell, Linux Bash etc.),
- Start coding and executing. 

#### Python Code Example:
```
print("I can actually code!")
```
You can press **enter** the given code, and print a line of your choice. In this case, I choose, "I can actually code!". However, **C** is a bit more complex. **C** requires a piece of software called **Compiler**.

### What really is a compiler?

For people like me, compiler can be best explained as the word **Translator** (Not using the word `interpreter`, as it has different meaning in programming language).

> Suppose, John is visiting Germany for business purposes. He knows only English, but his meeting is with Mr. Lange who only knows German. They can't really communicate with each other. Luckily, Mr. Lange has a son called Richard who understands English and translate it to German so that Mr. Lange can understand.

Richard is called **`compiler`** in computer science. 

### Why is this needed?

Because **`C`** is a high level language. We can write code in words that is understood by us, but not by machines.

**Example:**

```
#include <stdio.h>

int main() {
    printf("My god, this is much harder than Python!\n");
    return 0;
}
```

Given code is how you can print a statement in **C** (Don't worry about it now, it will make sense later). But, we kind of understand what is written, a computer on the other hand doesn't. 


Digital computer only understands two digits; **0** and **1**. The job of a compiler is to convert the code we write into **0s** and **1s** that the computer understands. You can see an example of machine code on [Wikipedia](https://en.wikipedia.org/wiki/Machine_code#Example).

### Why **C** requires a compiler and **Python** doesn't?

Because the core design is different in these two languages. In case of, **Python**, it takes your code, translates it to machine and execute the machine code, then shows the result. This takes more computing power and time to do it compared to **C**. The way **C** works makes it very fast and eligible to write code that needs every bit of computing power like an Operating System.
**Windows, macOS, Linux** all has major portion of code written in **C**.

### What are the available compilers for **C**?
[GCC](https://gcc.gnu.org/) and [Clang](https://clang.llvm.org/) are two of the most popular compilers available today. You can learn more about these online. For our purposes, we will head straight to the coding environment. 

### Integrated Development Environment
IDE is an application software where developer can efficiently write and debug(finding problem) codes. As we are a beginner here, we are not going to use hardcore IDE like, [Code::Blocks](https://www.codeblocks.org/) rather a code editor called [Visual Studio Code](https://code.visualstudio.com/). Here is how you can set up the coding environment like my PC:

1. Install [VS Code](https://code.visualstudio.com/),
2. Install [C/C++ Plugin](https://code.visualstudio.com/docs/languages/cpp) for the editor

### Running our first code

1. Create a folder that you want to experiment with C
2. Open VS Code and File> Add Folder to Workspace
3. File> Save Workspace As...
4. Add a file to the Folder that ends with `.c` like `hello.c`

You will get a similar looking IDE like me.


![Blank Editor with Workspace Saved](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0twlk8y5ofbm93k56bom.png)

P.S. I didn't get accepted in **Hogwarts** doesn't mean that I can't do magic **wizardry** in a folder called **Hogwarts**.

5. Paste the following lines in your **.c** file. In my case, `wizardry.c`.

```
#include <stdio.h>

int main() {
    printf("My god, this is harder than Python!\n");
    return 0;
}
```
6. Hit **`ctrl+F5`** in your keyboard. This will compile the code into an executable (instructions for computer written in machine code), run the executable and show the output in the terminal. In my case:

![Output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wv3d8rinh57pfpiz67av.png)

Whew, this is lots to take! It gets easier, though (God, I hope so!).

## Pro Tip

Both Google and YouTube is your only friend in this journey. Learn to use them well. I am going to provide as many resources as I can, but your issue will be unique and self-learning will not be possible without tremendous reading. Get ready for that.