Saturday, 9 April 2011

Span Of Statements

In this video tutorial, we check the way the C compiler treats the different tokens, by actually dividing a big line of code into two smaller lines, each time separating the lines in different spots, so as to understand better how the C compiler interprets the different divisions.

Line by line explanation

In this succinct tutorial, we review what has been taught before, but go little-by-little, through each line explaining in more detail the program that we have been creating.

If statement

The if statement serves for bifurcating the execution of the instructions within the program.
if the condition of the if statement results in a boolean true(non-zero), the if code block executes, otherwise(boolean false, AKA zero) it does not.

We build and run the program several times, in each occasion modifying the resulting if conditional expression, so as to check how the program behaves with different conditions.

Comment usage

We realize that Code::Blocks has line numbering, text colouring, and easy text editing capabilities, therefore, edit.com is avoided. The two types of C comments are explored:

/* comments here */ is the C style comment, it lasts for as many lines as the delimiters indicate.

// C++ style comment is the C++ style comment, it lasts up until the end of that line.

Comments are used documentation and explanation purposes. Obvious beginner explanations must be skipped for real world programs. Only in educational material will you find comments being used as obvious explanations.

Variables definitions

We create our first variable in the program. the assignment operator = is discovered. The printf function from the stdio.h header is succinctly explained, along with the %d format specifier. Three programs are used to edit our code: edit.com, notepad.exe, and Code::Blocks, just to clarify that any text editor will suffice.

Friday, 8 April 2011

Batch commands

We change the location of some files from MinGW_exercises to MinGW_exercise\01 . Batch commands are used from the terminal in order to perform these operations. Batch scripting is a powerful alternative to hard disk explorers, if saved on a script file, it allows the automatic execution of certain housekeeping tasks.

First C program built (from terminal)

We prepare the directory tree so that we have a well sorted hierarchy. In that way we are better organized to build, whether we use the Code::Blocks IDE, or directly from the command line. Some batch commands (like tree /f ) are shown. We finally build code from the terminal so as to provide another way to build our programs. This is the Unix way of building a C source file.