Introduction to C language
-
C. Yes the classic C language is the mother language of many programing languages like C++/C# . Do you know that our lovely language , python interpreter is written in C . In 1972 , C language was developed by “Dennis Ritchie” for UNIX. In early days C was used as the core language of UNIX operating system. Now many other operating systems use it as core language . Now C is one of the most widely used programming languages.
Why I learn C?1 ) Learn exploit development
If you plan to learn exploit writing for windows or Linux , there are no excuses. You must learn C for understand those concepts. Also you need to learn how to compile C programs and how to debug them in a debugger.
2 ) Learn reverse engineering or malware analysis.
You need C for both of above sections because C is great for learn basics of computer architecture.
3) Mange memory directly.
C language allow you to work with memory unlike many other languages. You can use heap by using functions like malloc(). Also there are varies options like structs, pointers and arrays for access memory.There are bunch of reasons to learn C and I’m not going to write all of them hear.
The concept of FunctionsIf I say C is built on a concept called a function, I’m not wrong. Every little C program uses functions. It may be two three or more. But definitely there should be a one function. So first of all let’s understand what is a function. Think about this real life example. There is a group of human that trained to do a work. If we supply raw data, group will process those data and give us the result. We may supply different kind of data and the output will be different also, but the process is same.Only thing that group of humans do is launch a per-configured flaw on data. This situation is what happens inside a function.
Now you have a clear idea about functions. Let’s see how a C program looks like.
#include <stdio.h> int main(){ printf("welcome to hacksland\n"); return 0; }
Oh too many lines of code. 😮 . In our python printing tutorial it took only one line to do the same as above.
print("welcome to hacksland")
You may think , why this much of code lines are required to a simple hello world program?. Well , You will realize this at end of the tutorial.
Anyway we are going to analyze above C code and see what it actually does.First , focus only on 3rd line of code. You can see a format like this.
printf("welcome to hacksland\n");
What does it mean? It is a function. Yeah if we give a string to this function, it will print that to the screen. In above example we gave welcome to hacksland. So it will print that data . What about /n . That’s called a string terminator and we’ll talk more about that later.
There is another thing to notice. Did you see a semicolon after the printf statement?. That’s how we indicate the end of a line in C language.
Now it’s time to look at other parts of our code. In first line we can see a #include <studio.h> statement. What it does?. We used a function called printf in our code. But how computer know what to do when we give a string to the function. We give a set of instructions to do when function is called. So computer process those instructions and give the result. In above example stdio.h file is holding those instructions for printf function. That’s why we included it before use printf.In Linux these Header files are located in “/usr/include” . If we look inside a header file we can see printf function looks like following.
int printf(){ /* hear is the code for print the string that supplied to function. */ return 0; }
There are couple of things to see.
At the beginning of function you can see a keyword as int . Also there is a return 0 at end. First we say computer that after completing the function it will give an integer. Next using return 0 we give that value. ( Hear it is 0 ) . Actually value zero means function was completed successfully.In our example there was something as int main(). Do you believe if I say that’s also a function. ? 🙂
Yes buddy. In this tutorial I said that there is even one function in every C program. That’s main function. Now you can understand why there is a int main() and return 0. Yes you guessed it. main function also return value zero after completing it.Ok guys. We got a clear idea on what is C and for what we can use it also we could understand basics of C language.In next tutorials we are going to go deep concepts of this awesome language. If you have any problems leave a comment. Thank you for reading.
C you again. 🙂