DEV Community

Cover image for Banker Learning C: Part 1
Nowshed H. Imran
Nowshed H. Imran

Posted on • Edited on • Originally published at nowshed.substack.com

Banker Learning C: Part 1

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 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!")
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

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.

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 and Clang 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 rather a code editor called Visual Studio Code. Here is how you can set up the coding environment like my PC:

  1. Install VS Code,
  2. Install C/C++ Plugin 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

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

  1. 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;
}
Enter fullscreen mode Exit fullscreen mode
  1. 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

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.

Top comments (2)

Collapse
 
elbeek profile image
elbeek

Isn't C low level language?

Collapse
 
nowshed profile image
Nowshed H. Imran • Edited

I may be wrong, but here is my understanding.
Assembly Language is considered Low Level Language, as it is just one step ahead of Machine Code.
C includes low level programming function. It means, as a programmer it can go as low as possible without becoming a very tough to understand assembly code.
The first condition of High Level Language is it has to be human readable. Although C is nowhere close to Python in readability, it can be understood like English.
That is why C is a High Level Language which can be used to write Low Level programming like writing Hardware Driver, Compiler for other languages etc.