Getting Started

Hello World

VJS Pranavasri

C , one of the fastest programming language out there, would be great addition to your skill set. For what is C? What is Procedural Programming etc, you've got the whole internet.The following takes on a practical approach with references linked wherever neccessary.

Pre-Requisites:(I would Cover for Windows/Linux)

If you are using windows and it's your first time i'd strongly recommend you install Dev-C++, Best place to start.

(OR)

If you are using linux make sure you have GCC installed.

For Ubuntu

sudo apt-get install gcc

For Arch/Manjaro

pacman -Sy gcc

You'd find the respective commands for your distro Just google it.

NOTE


I'll put this up in the very beginning, In programming one of the most important thing is to know how to google remember: A programmers google search and a normal persons google search is different and that is what sets us apart Stack Overflow is your best friend (Trust Me).

If the above points go over your head don't worry, Just re read them after a couple of pages.

All the formalities aside let's write our very first code:

#include<stdio.h>
void main(){
	printf("Hello World!!");
}
								

Yes We follow the stereo type and hence Hello World is our very first code

Now let's try to break down our code shall we. So irrespective of whichever C code you write you have that first line on the top
#include<stdio.h>
In terms of C language this is called a header file.

You would not want go sit coding all the basic things now would you. therefore the header file stdio, which directly translates to standard input output, has all the necessary codes that help you for giving some output, getting anything as input so on and so forth.

so now for some bigger terms, you absolutely don't need to worry if you don't understand any of the following I didn't really either till i started writing some codes myself.

So void main(){} this is a function declaration. A function is a piece of code encapsulated in a single word, in simple terms in this case the name of our function is main, and whenever you write main in your code all the code in btween { and } will be run. That's an abstract view of it we'll understand functions perfectly when we go to the topic dealing with it. For now we just need to remember in our C code we always need a main function as that is thhe point at which the code starts execution.

so what is void?? Oo sounds cool right, Just a bit of patience and You'll Know :).

';' is very important at the end of every line else you'd end up with hell loads of errors

For People coming from python We don't have indentations here and line breaks are denoted by ';'

Right i Hope so far so good.
so anything that has rounded brackets (paranthesis) would be a function most of the times, Sounds good?
Cool so notice the printf line we used.
printf("Hello World!!")
so printf has a set of '()' so it is a function so whenever we do printf a set of lines of code written somewhere start executing, makes sense right? So where is that somewhere, HMM? Remember the stdio.h file yep that is where. So what exactly does it do, it outputs whatever you give it. Therefore the above code would out put Hello World!!

One Final thing before we finally run our code, How does it run? In C there is this thing called a compile, so what does it do. The code which you have written is closer to human language whereas as we all know computers only understand binary that is 0 and 1. So obviously you'd not want to do that transformation. Compiler is something that does it for you and creates a exe file which you can run.

Ok Cool We're all done Now let's compile.

Windows


as you have written the code in a dev-c++ new file save that file with .c extension there will be an option that says compile and run (In the toolbar above Execute-> Compile and Run)





Linux

cd into the directory where you have your file saved. (.c extension don't forget) command to compile : gcc filename.c -o executable now you run it by doing ./executable (Where your executable is any name that you've set just as the image shown below)