C/C++ Programming for Hackers: Part 3 (Examining the Code)

so, let's get started!
  • #include <stdio.h> 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!
SHARE

About Unknown

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment