Now Reading
C/C++ Programming for Hackers: Part 3 (Examining the Code)2 min read
The short URL of the present article is: https://4hax.net/uGJeH

Welcome back, fellow hackers! as promised, in Part 3, we will be examining the code we just compiled in part 2. this will be a short how-to, but hopefully it will give you an understanding of how C/C++ programs run.

so, let’s get started!

  • #include this line tells the compiler to include a library file, in this case, stdio.h. this file is built into the libraries of GCC and holds all the basic input/output instructions, like printf().
  • int main() this is the main function of the program. all programs have this function. from embedded systems to computergames and operating systems. it is always the first function that is called (called=used in technical terms) when a program runs, much like the main.c file is the first file that is called when a program runs.
  • the { and } these are called “brackets”. in between these, we put our code to be executed by that function. in this case, it is only the main() function. the code in between 2 brackets is called a block of code.
  • printf(“Hello Null Byte!n”); this is the instruction that prints text on the screen. the parameters of an instruction (parameters are values that an instructions requires to run) are placed in between (). in this case, printf just needs a string to run (yes, a string REALLY is the correct name for a word/sentence in a program). in almost every programming language, the value of a string variable (i’ll talk about variables in a later how-to) is placed in between quotation marks, or “”. so why wasn’t n printed out on the screen? because n is an instruction inside printf to tell the program to go to a new line. you can try to edit the main.c and remove the n, recompile it and see for yourselves what it will do.
  • return 0; this line instructs the program to exit with code 0 (code 0 stands for “the program completed successfuly”). take note that main() is an integer (int) and needs to return a value after it finished. that is for what the “return” instruction is made. have you ever wondered what these error codes mean when a program crashes? well now you know. they are simply waypoints for developers to find where something went wrong in their program when the user encountered the bug.

also take note: all instructions end with a ;. this ; basically means “go to the next instruction.” it is kind of a dot on the end of a sentence, but for a program.

that’s it folks! in the next tutorial, i will talk about the differences between programming and scripting languages and their advantages/disadvantages, as there still seems to be confusion about this.

if you have any problems or questions, feel free to comment your question down below!


The short URL of the present article is: https://4hax.net/uGJeH
What's your reaction?
About The Author

Leave a Response