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!")
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 purpose. 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 for machines.
Example:
#include <stdio.h>
int main() {
printf("My god, this is 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.
Why C requires a compiler and Python doesn't?
Because the language 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:
Install VS Code,
Install C/C++ Plugin for the editor
Running our first code
Create a folder that you want to experiment with C
Open VS Code and File> Add Folder to Workspace
File> Save Workspace As...
Add a file to the Folder that ends with
.c
likehello.c
You will get a similar looking IDE like me.
P.S. I didn't get accepted in Hogwarts doesn't mean that I can't do magic wizardry in a folder called Hogwarts.
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;
}
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:
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 I can, but your issue will be unique and self-learning will not be possible without tremendous reading. Get ready for that.